-1

解析されたデータの配列を挿入した後、UITableView の左側に余分な空白が表示されます。だから、私の質問は、tableView の空白を削除する方法です。解析したテキストへの href ハイパーリンクがセルに空白として表示されているため、空白があると思います。

これは、私が解析した 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;
}
4

1 に答える 1

1

あなたの説明に基づいて、ラベルに表示しているテキストに余分な空白があると思います。

この場合、作成した文字列を取得し、ラベルを設定する前にこれを使用します。

theStringToDisplay = [theStringToDisplay stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
theLabel.text      = theStringToDisplay;

コードを提供したので編集します。
あなたの場合、stringByTrimmingCharactersInSet配列に最初に文字列を設定するときに使用します。

NSArray *divNodes = [bodyNode findChildrenOfClass:@"c4"];
for (HTMLNode *inputNode in divNodes) {
    [listData addObject:[[inputNode contents] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]];
} 
于 2012-05-30T03:37:54.380 に答える