我在一個視圖控制器中有兩個不同的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