【发布时间】:2012-10-29 23:46:02
【问题描述】:
我在 IB 中设置了一些视图控制器。一个具有大约 6 个单元格的 TableView(以编程方式填充)。然后还有 6 个视图控制器(每个单元格一个)。
我想让它在我的
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}
我可以将视图切换到与单击的单元格相关的任何视图。
所以如果他们点击cell1,它会转到view1,如果他们点击cell2,它会转到view2。
顺便说一句,这就是我初始化表的方式,它工作正常。
//tableview datasource delegate methods
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return showArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"Cell";
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
if(cell == nil){
cell = [[CustomCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.showLabel.text = [showArray objectAtIndex:indexPath.row];
cell.image.image = [UIImage imageNamed:[imageArray objectAtIndex:indexPath.row]];
cell.seasonLabel.text = [seasonArray objectAtIndex:indexPath.row];
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 106;
}
- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation: (UITableViewRowAnimation)animation{
NSIndexPath *newCellPath = [NSIndexPath indexPathForRow:showArray.count
inSection:0];
[self.theatreView insertRowsAtIndexPaths:@[newCellPath]
withRowAnimation:UITableViewRowAnimationFade];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}
【问题讨论】:
-
您的应用程序结构如何。它是否位于导航控制器中?
-
@Bergasms 不,它有一个作为主菜单的视图控制器,它只是使用 UIButtons 从一个控制器转到另一个控制器
标签: ios uiview tableview viewcontroller