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