我的tableViewcell在数组中,我想选择日记单元格,我需要导航到下一个屏幕。我不知道在选择行方法中要实现什么。请帮助我
table=[[UITableView alloc]init];
table.frame=CGRectMake(0, 0, 250, CGRectGetHeight(self.view.frame));
table.delegate=self;
table.dataSource=self;
table.backgroundColor=RGBCOLOR(255,255,255);
tabledata=[NSMutableArray arrayWithObjects:@"Me and My stuff",@"Upgrade Membership",@"Diary",@"Progress",@"Friends",@"My awards and points",@"Messages",@"Blogs",@"Fun stuff",@"Remainders",@"Settings",@"Signout",nil];
table.backgroundColor=RGBCOLOR(255,239,213);
table.sectionFooterHeight=44;
table.sectionHeaderHeight=44;
table.separatorStyle=UITableViewCellSeparatorStyleNone;
[self.view addSubview:table];
self.view.backgroundColor=RGBCOLOR(255,239,213);
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellidentifier =@"table";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellidentifier];
if (cell==nil) {
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellidentifier];
cell.opaque=NO;
cell.backgroundColor=RGBCOLOR(255,239,213);
cell.textLabel.textColor=RGBCOLOR(32,178,170);
cell.selectionStyle=UITableViewCellSelectionStyleBlue;
}
cell.textLabel.text=[tabledata objectAtIndex:indexPath.row];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
}
答案 0 :(得分:0)
假设tableview包含在我们的第一个视图控制器中
<强> 1。 SecondViewController.h 强>
@property(nonatomic, strong) NSString *fullName;
<强> 2。 SecondViewController.m 强>
@synthisize fullName;
- (void)viewDidLoad
{
NSLog(@"name ==%@",fullName);
[super viewDidLoad];
}
第3。 FirstViewController.m 强>
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.row==2) // this is diary cell
{
SecondViewController *temp = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
temp.fullName=[tabledata objectAtIndex:indexPath.row];
[self.navigationController pushViewController:temp animated:YES];
}
else
{
// do nothing
}
}