【发布时间】:2015-01-10 01:59:20
【问题描述】:
我有一个显示提要的 RSS 阅读器,然后当单击自定义单元格时,您应该会看到文章。一切正常,但后来我对其进行了更改,以便它可以与自定义单元格一起使用。为了做到这一点,我不得不从情节提要中删除所有原型单元格,随后删除了单元格和细节视图之间的segue。当我在应用程序中添加原型单元格时,会崩溃而没有任何错误。我很迷茫。如何在不使用原型单元或 segue 的情况下将其带到详细视图?我试过 didSelectRowAtIndexPath 但这是 UIViewController 不是 UITableViewController。我的表格视图代码如下,如果您有任何想法,请告诉我..
#import "APPMasterViewController.h"
#import "APPDetailViewController.h"
#import "IITableViewCell.h"
@interface APPMasterViewController () {
NSXMLParser *parser;
NSMutableArray *feeds;
NSMutableDictionary *item;
NSMutableString *title;
NSMutableString *link;
NSString *element;
}
@end
@implementation APPMasterViewController
- (void)awakeFromNib
{
[super awakeFromNib];
}
- (void)viewDidLoad {
[super viewDidLoad];
[[UINavigationBar appearance] setBarTintColor:[UIColor greenColor]];
feeds = [[NSMutableArray alloc] init];
NSURL *url = [NSURL URLWithString:@"http://example.com/?feed=rss"];
parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
[parser setDelegate:self];
[parser setShouldResolveExternalEntities:NO];
[parser parse];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table View
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return feeds.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *simpleTableIdentifier = @"IITableViewCell";
IITableViewCell *cell = (IITableViewCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"IITableViewCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.mainTextLabel.text = [[feeds objectAtIndex:indexPath.row] objectForKey: @"title"];
return cell;
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
element = elementName;
if ([element isEqualToString:@"item"]) {
item = [[NSMutableDictionary alloc] init];
title = [[NSMutableString alloc] init];
link = [[NSMutableString alloc] init];
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if ([elementName isEqualToString:@"item"]) {
[item setObject:title forKey:@"title"];
[item setObject:link forKey:@"link"];
[feeds addObject:[item copy]];
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
if ([element isEqualToString:@"title"]) {
[title appendString:string];
} else if ([element isEqualToString:@"link"]) {
[link appendString:string];
}
}
- (void)parserDidEndDocument:(NSXMLParser *)parser {
[self.tableView reloadData];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 78;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"showDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSString *string = [feeds[indexPath.row] objectForKey: @"link"];
[[segue destinationViewController] setUrl:string];
}
}
@end
【问题讨论】:
-
会有崩溃信息-尝试设置异常断点
-
您是否重新制作了自定义单元原型的转场? segue 使用自定义单元格与标准 UITableViewCell 的工作方式没有区别。
标签: ios objective-c uitableview