我試圖改變將使用的自定義單元格,這取決於存儲在我的數組中的信息。我已經嘗試了一切,但似乎無法讓它工作沒有錯誤。代碼似乎不接受單元格筆尖的字符串輸入。有沒有其他方法可以做到這一點?下面將附上我的代碼。來自NSString的UITableViewCell Nib
謝謝。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if([[Tutortrackinbud[indexPath.row] valueForKey:@"reply"] isEqual: @"N"])
{
nib = @"ReviewCell1";
}
else{
nib = @"ReviewCell2";
}
static NSString *simpleTableIdentifier = nib;
ReviewCell1TableViewCell *cell = (ReviewCell1TableViewCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
NSArray *nibArray = [[NSBundle mainBundle] loadNibNamed:nib owner:self options:nil];
cell = [nibArray objectAtIndex:0];
}
if ([[Tutortrackinbud[indexPath.row] valueForKey:@"stars"] isEqual: @"1"]){
NSLog(@"1");
cell.star1.image = [UIImage imageNamed:@"star.png"];
cell.star2.image = [UIImage imageNamed:@"greystar.png"];
cell.star3.image = [UIImage imageNamed:@"greystar.png"];
cell.star4.image = [UIImage imageNamed:@"greystar.png"];
cell.star5.image = [UIImage imageNamed:@"greystar.png"];
cell.star6.image = [UIImage imageNamed:@"greystar.png"];
}
else if ([[Tutortrackinbud[indexPath.row] valueForKey:@"stars"] isEqual: @"2"]){
NSLog(@"2");
cell.star1.image = [UIImage imageNamed:@"star.png"];
cell.star2.image = [UIImage imageNamed:@"star.png"];
cell.star3.image = [UIImage imageNamed:@"greystar.png"];
cell.star4.image = [UIImage imageNamed:@"greystar.png"];
cell.star5.image = [UIImage imageNamed:@"greystar.png"];
cell.star6.image = [UIImage imageNamed:@"greystar.png"];
}
else if ([[Tutortrackinbud[indexPath.row] valueForKey:@"stars"] isEqual: @"3"]){
NSLog(@"3");
cell.star1.image = [UIImage imageNamed:@"star.png"];
cell.star2.image = [UIImage imageNamed:@"star.png"];
cell.star3.image = [UIImage imageNamed:@"star.png"];
cell.star4.image = [UIImage imageNamed:@"greystar.png"];
cell.star5.image = [UIImage imageNamed:@"greystar.png"];
cell.star6.image = [UIImage imageNamed:@"greystar.png"];
}
else if ([[Tutortrackinbud[indexPath.row] valueForKey:@"stars"] isEqual: @"4"]){
NSLog(@"4");
cell.star1.image = [UIImage imageNamed:@"star.png"];
cell.star2.image = [UIImage imageNamed:@"star.png"];
cell.star3.image = [UIImage imageNamed:@"star.png"];
cell.star4.image = [UIImage imageNamed:@"star.png"];
cell.star5.image = [UIImage imageNamed:@"greystar.png"];
cell.star6.image = [UIImage imageNamed:@"greystar.png"];
}
else if ([[Tutortrackinbud[indexPath.row] valueForKey:@"stars"] isEqual: @"5"]){
NSLog(@"5");
cell.star1.image = [UIImage imageNamed:@"star.png"];
cell.star2.image = [UIImage imageNamed:@"star.png"];
cell.star3.image = [UIImage imageNamed:@"star.png"];
cell.star4.image = [UIImage imageNamed:@"star.png"];
cell.star5.image = [UIImage imageNamed:@"star.png"];
cell.star6.image = [UIImage imageNamed:@"greystar.png"];
}
else if ([[Tutortrackinbud[indexPath.row] valueForKey:@"stars"] isEqual: @"6"]){
NSLog(@"6");
cell.star1.image = [UIImage imageNamed:@"star.png"];
cell.star2.image = [UIImage imageNamed:@"star.png"];
cell.star3.image = [UIImage imageNamed:@"star.png"];
cell.star4.image = [UIImage imageNamed:@"star.png"];
cell.star5.image = [UIImage imageNamed:@"star.png"];
cell.star6.image = [UIImage imageNamed:@"star.png"];
}
cell.reviewdate.text = [Tutortrackinbud[indexPath.row] valueForKey:@"date"];
cell.reviewtext.text = [NSMutableString stringWithFormat:@"%@ -%@",[Tutortrackinbud[indexPath.row] valueForKey:@"desc"],[Tutortrackinbud[indexPath.row] valueForKey:@"username"]];
//cell.tutortext.text = [NSMutableString stringWithFormat:@"%@ -%@",[Tutortrackinbud[indexPath.row] valueForKey:@"desc"],[Tutortrackinbud[indexPath.row] valueForKey:@"username"]];
cell.tutortext.text = @"this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test";
return cell;
}
http://stackoverflow.com/questions/14303832/uitableview-with-two-custom-cells-multiple-identifiers - might解決你的問題。 –
你會得到什麼錯誤? – Lion