//返回行數
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{return [listData count];
}
//返回一個cell,即每一行所要顯示的內容
{
static NSString * identify=@"identify";
UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:identify];
if(cell==nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identify];
}
NSUInteger row = [indexPath row];
cell.textLabel.text = [listData objectAtIndex:row];
UIImage *image=[UIImage imageNamed:@"qq.png"];
cell.imageView.image=image;
if(row<7)
cell.detailTextLabel.text = @"Mr . Disney";
else
cell.detailTextLabel.text = @"Mr . Tolkien";
return cell;
}
//設置一個叫indent level的屬性,這樣每一行都比上一行右移一點
{
NSUInteger row = [indexPath row];
return row;
}
//設置點擊事件前可以設置哪一行不能響應點擊事件
{
NSUInteger row=[indexPath row];
if(row==0)
{
return nil;
}
return indexPath;
}
//設置點擊事件
{
NSUInteger row = [indexPath row];
NSString * rowvalue=[listData objectAtIndex:row];
NSString * message=[[NSString alloc] initWithFormat:@"你選擇了%@",rowvalue];
UIAlertView *alert =[[UIAlertView alloc] initWithTitle:@"注意!" message:message delegate:nil cancelButtonTitle:@"取消" otherButtonTitles: nil];
[alert show];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
//設置列寬
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 70;
}