-1
UITableView在插入已分析数据数组后显示左侧额外的空白区域。所以,我的问题是如何修剪tableView中的空白。我想我有空白的空间,因为href超链接到我解析的文本,在单元格中显示为空白。UITableView显示额外的空白区域
这是我解析的HTML的一部分:
<h3 style="clear:left"><a class="c4" href="http://www.website.ge/article-22624.html">
Facebook - the text I have parsed </a></h3>
这是我所使用的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSError *error = nil;
NSURL *url=[[NSURL alloc] initWithString:@"http://www.website.ge/news"];
NSString *strin=[[NSString alloc] initWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
HTMLParser *parser = [[HTMLParser alloc] initWithString:strin error:&error];
if (error) {
NSLog(@"Error: %@", error);
return;
}
listData =[[NSMutableArray alloc] init];
HTMLNode *bodyNode = [parser body];
NSArray *dateNodes = [bodyNode findChildTags:@"span"];
for (HTMLNode *inputNode in dateNodes) {
if ([[inputNode getAttributeNamed:@"class"] isEqualToString:@"date"]) {
//NSLog(@"%@", [inputNode contents]);
//[listData addObject:[inputNode contents]];
}
}
NSArray *divNodes = [bodyNode findChildrenOfClass:@"c4"];
for (HTMLNode *inputNode in divNodes) {
[listData addObject:[inputNode contents]];
}
}
在表格视图我看到空白空间在所解析的数据的开头。它必须是被翻译成空白空间的超链接。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
//here you check for PreCreated cell.
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
//Fill the cells...
cell.textLabel.textAlignment=UITextAlignmentLeft; // attempt to move it to the left
cell.textLabel.text = [listData objectAtIndex: indexPath.row];
//yourMutableArray is Array
return cell;
}
我应该如何将此方法应用于数组? – Benjamen
它看起来我需要但它说whitespaceCharacterSet是未声明的标识符。 – Benjamen
这是一个类方法,所以你需要[NSCharacterSet whitespaceCharacterSet] – rdelmar