作者zonble (zonble)
看板MacDev
標題Re: [問題] 如何等待alert結束?
時間Sat Sep 4 03:56:47 2010
※ 引述《markzog21 (殘羽星辰)》之銘言:
: - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
: return [sectionArray count];
: }
UITableView 要求至少要有一個 section,你這邊最好改寫,
因為 array count 可能是 0。一旦回傳 0 就會出現 exception。
: - (UITableViewCell *)tableView:(UITableView *)tableView
: cellForRowAtIndexPath:(NSIndexPath *)indexPath
: {
: NSInteger row = [indexPath row];
: NSInteger section = [indexPath section];
: // Create a cell if one is not already available
: UITableViewCell *cell = [self.tableView
: dequeueReusableCellWithIdentifier:@"any-cell"];
: if (cell == nil)
: cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero
: reuseIdentifier:@"any-cell"] autorelease];
: // Set up the cell by coloring its text
: [cell.textLabel setText: [sectionArray objectAtIndex:0]];
呃,照你前面產生 NSMutableArray 的方式,[sectionArray objectAtIndex:0]
應該會回傳 NSArray,但是你現在卻把 NSArray 當做 NSString 用。
: return cell;
: }
--
zonble.net
cocoa.zonble.net
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.44.188.242
→ markzog21:用好了,謝謝@@"原來tableview還有這層關係在 09/06 18:53
→ markzog21:可是如果我改第一個回傳sectionArray成 09/06 18:54
→ markzog21:if([sectionArray count] == 0) return 1; 09/06 18:54
→ markzog21:else return [sectionArray count]; 09/06 18:54
→ markzog21:在進入畫面時反而會當掉...我這樣改也有問題?? 09/06 18:55
→ markzog21:反而沒改就對了 只是所有的cell的title 都有小刮號() 09/06 18:55
→ markzog21:讓我百思不得其解 我改cell.textLabel 的地方是改成 09/06 18:56
→ markzog21:[cell.textLabel setText: [NSString stringWithFormat: 09/06 18:56
→ markzog21:@"%@",[sectionArray objectAtIndex:0]]]; 09/06 18:56
推 markzog21:我懂了== 我剛剛引入的是array 不是cell 改好了ˊˋ 09/06 19:59