iPhone开发教程之开发基于IBMLotusConnections2.5的社交网络iPhone应用程序3课件.pptx
文本预览下载声明
iPhone开发教程之开发基于 IBM Lotus Connections 2.5 的社交网络 iPhone 应用程序(3)清单 8. 保存标题元素文本值在 iPhone 上显示数据清单 9. 实现 viewDidLoad清单 10. 创建 UITableViewCells 清单 11. 获取 UITableView 中的行数和段数 调整应用程序性能清单 12. 设置和获取缓存的 NSArray 条目结束语清单 8. 保存标题元素文本值////////////////////////////////////////////////////////////////////////////////////- (void) parser: (NSXMLParser*) parser didEndElement: (NSString*) elementName namespaceURI: (NSString*) namespaceURI qualifiedName: (NSString*) qName { if ([elementName isEqualToString:@title] _foundEntry) { _foundTitle = NO; [_items addObject:_title]; [_title release]; } if ([elementName isEqualToString:@entry]) { _foundEntry = NO; }}在 iPhone 上显示数据最后,要准备好数据,让它显示在 iPhone 上希望用户看到的地方。 当解析完成后,就有了可在表格中显示的 NSString 条目数组。要实现 tableview,加载条目数组调用 [_tableView reloadData] 中的表格数据,如清单 4 中所示。这段代码调用了tableview 委托方法实现 tableView:cellForRowAtIndexPath:。由于 SampleApplicationViewController.m 是 tableView 委托方法,因此可以调用该类中定义的方法。可以看到在 viewDidLoad 方法中设置了 tableView 委托和数据源。这段代码在 NSURLRequest 和 NSURLConnection 代码之前。清单 9. 实现 viewDidLoad// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.?- (void)viewDidLoad {? [super viewDidLoad];??_tableView = [[[UITableView alloc] initWithFrame:self.view.bounds] autorelease]; [self.view addSubview:_tableView];??_tableView.delegate = self;?_tableView.dataSource = self;??//Blogs Atom feed API?NSURL *url = [[[NSURL alloc]initWithString:@/developerworks/mydeveloperworks/news/atom/stories/public?source=blogsps=30]? autorelease];??NSURLRequest* request = [[NSURLRequest alloc] ?initWithURL:url];加载 UITableView 时,它调用 tableView:cellForRowAtIndexPath: 的次数等于屏幕上可见单元格的个数。例如,如果屏幕高度是 100 个像素,每个单元格高度是 10 个像素,那么它调用了 10 次该方法。该方法返回一个 TableViewCell 类实例。该实例是表格中显示的数据的布局。当用户滚动表格时,每当有单元格显示在屏幕上,就会调用 tableView:cellForRowAtIndexPath:。每次 UiTableView 调用该方法时,它都会传递一个 indexPath,这是它要返回的 UITableViewCell 值。在此应用程序示例中,传回了一个 UITableViewCell,它带有在 UITableViewCell 中的 textLabel 设置的博客条目标题。清单 10. 创建 UITableViewCells// Customize the appearance of table view ce
显示全部