-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