我在一个视图控制器中有两个不同的tableView,我收到一条错误消息。数据源和委托被设置为视图控制器。我在tableview方法中做错了什么。我以前没有在同一视图中处理过多个tableView。由于UITableView DataSource必须从cellforRowAtIndexPath返回一个单元格错误
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
if (tableView == self.postsTableView) {
return 1;
}
else if (tableView == self.eventsTableView){
return 1;
}
return 1;
}
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if (tableView == self.postsTableView) {
return 1;
}
else if (tableView == self.eventsTableView){
return 1;
}
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if ([tableView isEqual: self.postsTableView]) {
profilePagePostCell *cellOne = (profilePagePostCell *) [tableView dequeueReusableCellWithIdentifier:@"profilePostCell"];
cellOne.postLabel.text = [NSString stringWithFormat:@"Hi"];
return cellOne;
}
if ([tableView isEqual: self.eventsTableView]) {
profileEventCell *cellTwo = (profileEventCell *) [tableView dequeueReusableCellWithIdentifier:@"profileEventCell"];
cellTwo.eventLabel.text = [NSString stringWithFormat:@"The big One"];
return cellTwo;
}
profileEventCell *cell = (profileEventCell *) [tableView dequeueReusableCellWithIdentifier:@"profileEventCell"];
return cell;
}
你在哪里制作细胞?如果在故事板中,您是否给了它们相同的标识符,以便您在此传递给出队方法? – rdelmar 2014-10-07 20:46:51