嗨我有一個用分隔符「:」分隔的字符串數組。我嘗試使用componentsSeparatedByString方法分離字符串,然後將結果保存到數組中,稍後使用該數組生成所需的輸出,但它沒有奏效。目標C(iPhone)中的拆分和交換字符串
例如
現在我的UITableView顯示細胞:
案例1:
How:Many
Too:Many
Apple:Milk
iPhone:Simulator
我想顯示在UITableView中的細胞:
案例2:
Many How
Many Too
Milk Apple
Simulator iPhone
這是我的cellForRowAtIndexPath方法:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
NSString *entry=[entryKeys objectAtIndex:[indexPath section]];
NSArray *entrySection=[entries objectForKey:entry];
cell.textLabel.text=[entrySection objectAtIndex:[indexPath row]]
}
return cell;
}
上述方法的輸出是殼體1但我想輸出爲殼體2個 entryKeys具有從AZ和入口段鍵有價值分類和列出的各自的鍵,即條目開始與A組合在關鍵A等...
它可能聽起來很愚蠢,但我仍然在學習..請幫助我
哇..那麼工作..我做的錯誤是在分離字符串後,我直接將它分配給單元格textlabel,在那裏我得到outofbounds例外..謝謝你.. – racharambola 2010-08-20 21:45:56