0
我的程序有2個NSMutableArray(s),每個包含一個項目列表。一些成本超過50美元,一些成本低於50美元。任務是將這些信息顯示爲表格的一部分。所以..Objective-C,UITableView,需要澄清
我的表有2個部分
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 2;
}
每個部分都有一個名字
- (NSString *)tableView:(UITableView *)
tableView titleForHeaderInSection:(NSInteger)section {
NSString *lSectionTitle;
switch (section) {
case 0:
lSectionTitle = @"Under $50";
break;
case 1:
...
每一部分都有一個計數
-(NSInteger) tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section {
NSInteger count= 0;
switch (section) {
case 0:
count = [[[PossessionStore defaultStore] under50Possessions] count];
break;
case 1:
.....
然後終於我們弄清楚什麼作爲給定單元的一部分顯示
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
if (!cell) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"UITableViewCell"]autorelease];
}
Possession *p = [[[PossessionStore defaultStore] allPossessions] objectAtIndex:[indexPath row]];
[[cell textLabel] setText:[p description]];
return cell;
}
上面的代碼代碼allPossessions
,其中包含兩個項目超過50美元和50美元以下。我被困在這一點上。
在這個例子中,有沒有一種方法可以讓我知道我是否被要求爲低於或超過$ 50的類別繪製單元格?
正是!在這個時候我正在讀這個,我看到[indexPath部分]可以被查詢。謝謝迦勒! – JAM