0
我有我的視圖控制器上的兩個uitableview元素...人加載罰款tableview顯示人名在表中,當我選擇一個人我在我的NSLog中獲得personID personName填充UILabel就好了,但團隊加載的表視圖NSCFString,當我選擇它的應用程序崩潰,這是在日誌中:「終止應用程序由於未捕獲的異常'NSInvalidArgumentException',原因:' - [ _NSCFString teamID]:無法識別的選擇發送到實例......」兩個UITableView一個負載罰款其他不
.M
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if (tableView == _personList){
return [personData count];
}else{
return [teamData count];
}
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (tableView == _personList){
if(!cell){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
Persons *person = [personData objectAtIndex:indexPath.row];
cell.textLabel.text = person.personName;
return cell;
}else {
if(!cell){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
Teams *team = [teamData objectAtIndex:indexPath.row];
cell.textLabel.text = team.teamName;
return cell;
}
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView == _personList){
Persons *person = [personData objectAtIndex:indexPath.row];
NSString *selPersonID = person.personID;
_thePersonName.text = person.personName;
NSLog(@"PersonID: %@", selPersonID);
}else if(tableView == _teamList){
Teams *team = [teamData objectAtIndex:indexPath.row];
NSString *selTeamID = team.teamID;
_theTeamName.text = team.teamName;
NSLog(@"TeamID: %@", selTeamID);
}
}
哦,親愛的...時間離開電腦!...就是這樣!謝謝! – user520300