【发布时间】:2012-02-11 12:13:35
【问题描述】:
我有一个 iphone 应用程序,它从作为 rss 提要的 xml 文件中读取“类别”字段。我的应用程序的工作方式是它在表格视图中按 xml“类别”字段中的类别显示 rss 提要的内容。
我对 tableviews 有点陌生,所以我有点迷茫。
我在 xml 文件中只有 2 个类别,一个名为“Uncategorized”,另一个名为“Promos”。
目前的代码是:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 2;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
switch (section) {
case 0:
return itemsToDisplay.count;
default:
return itemsToDisplay.count;
}
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
if(section == 0)
return @"Promoções";
else
return @"Não Categorizados";
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
if (indexPath.section == 0) {
MWFeedItem *item = [itemsToDisplay objectAtIndex:indexPath.row];
if([item.category isEqualToString:@"PROMOS"]){
MWFeedItem *item = [itemsToDisplay objectAtIndex:indexPath.row];
NSLog(@"ENTRA NO PROMOS____________________");
NSLog(@"item.category = %@-------------->", item.category);
// Process
NSString *itemTitle = item.title ? [item.title stringByConvertingHTMLToPlainText] : @"[No Title]";
NSString *itemSummary = item.summary ? [item.summary stringByConvertingHTMLToPlainText] : @"[No Summary]";
NSLog(@"IMAGE (table View) = %@",item.image);
NSURL *url = [NSURL URLWithString:item.image];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDelegate:self];
[request startAsynchronous];
NSData * imageData = [NSData dataWithContentsOfURL:url];
UIImage * image = [UIImage imageWithData:imageData];
// Set
cell.imageView.image = image;
cell.textLabel.font = [UIFont boldSystemFontOfSize:15];
cell.textLabel.text = itemTitle;
NSMutableString *subtitle = [NSMutableString string];
if (item.date) [subtitle appendFormat:@"%@: ", [formatter stringFromDate:item.date]];
[subtitle appendString:itemSummary];
cell.detailTextLabel.text = subtitle;
NSLog(@"FIM DO PROMOS_____________________");
}
}else if(indexPath.section == 1){
MWFeedItem *item = [itemsToDisplay objectAtIndex:indexPath.row];
if([item.category isEqualToString:@"Uncategorized"]){
NSLog(@"ENTRA NO UNCATEGORIZED__________");
NSLog(@"item.category = %@------------------>", item.category);
// Process
NSString *itemTitle = item.title ? [item.title stringByConvertingHTMLToPlainText] : @"[No Title]";
NSString *itemSummary = item.summary ? [item.summary stringByConvertingHTMLToPlainText] : @"[No Summary]";
NSLog(@"IMAGE (table View) = %@",item.image);
NSURL *url = [NSURL URLWithString:item.image];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDelegate:self];
[request startAsynchronous];
NSData * imageData = [NSData dataWithContentsOfURL:url];
UIImage * image = [UIImage imageWithData:imageData];
// Set
cell.imageView.image = image;
cell.textLabel.font = [UIFont boldSystemFontOfSize:15];
cell.textLabel.text = itemTitle;
NSMutableString *subtitle = [NSMutableString string];
if (item.date) [subtitle appendFormat:@"%@: ", [formatter stringFromDate:item.date]];
[subtitle appendString:itemSummary];
cell.detailTextLabel.text = subtitle;
NSLog(@"FIM DO UNCATEGORIZED________________");
}
}
return cell;
}
我遇到的问题是它为两个类别显示相同数量的单元格,并且不按类别过滤它们。
最好的问候。
【问题讨论】:
标签: iphone objective-c ios xcode uitableview