-1

このコードを使用して uitablevirw でコンテンツを表示する方法を示すための画像をアップロードします

- (void)viewDidLoad
    {
        NSURL *url=[[NSURL alloc]initWithString:@"http://avweatherforecasts.com/services/iphoneservice.php"];    
        DaTa=[[NSData alloc]initWithContentsOfURL:url];    
        NSLog(@"data----%@",DaTa);
        Xmlpaeser=[[NSXMLParser alloc]initWithData:DaTa];    
        Xmlpaeser.delegate=self;    
        [Xmlpaeser parse];
        [Xmlpaeser release];

        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
    }



 - (void)parserDidStartDocument:(NSXMLParser *)parser{
        array=[[NSMutableArray alloc]init];
        strcontent=nil;
    }

    - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{   

        if ([elementName isEqualToString:@"start"])
        {        
            Dict=[[NSMutableDictionary alloc]init];    
      }
    }

    - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{

        strcontent=[NSString stringWithFormat:@"%@",string];

        NSLog(@"Strcontent----%@",strcontent);
    }

    - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{


            if ([elementName isEqualToString:@"city"]){
                [Dict setObject:strcontent forKey:elementName];
            }
            if ([elementName isEqualToString:@"min"]){
                [Dict setObject:strcontent forKey:elementName];
            }
            if ([elementName isEqualToString:@"max"]){
                [Dict setObject:strcontent forKey:elementName];
            }
            if ( [elementName isEqualToString:@"forecast"]
                ) {

                [Dict setObject:strcontent forKey:elementName];
               NSLog(@"dict--%@",[Dict description]);
            }          
            else if([elementName isEqualToString:@"start"]){            
                [array addObject:Dict];

                [Dict release];     
        }
    }

    - (void)parserDidEndDocument:(NSXMLParser *)parser{

        NSLog(@"array--%@",[array description]);       

    }

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

        return [array count];

    }

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

        static NSString *identifier=@"cell";

        custome_cell *Cell=(custome_cell *)[tableView dequeueReusableCellWithIdentifier:identifier];

        if (Cell==nil) {

            NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"custome_cell" owner:self options:nil];
            Cell = [nib objectAtIndex:indexPath.row];
        }    
        Cell.city.text=[[array objectAtIndex:indexPath.row] objectForKey:@"city"];
        Cell.min.text=[[array objectAtIndex:indexPath.row] objectForKey:@"min"];
        Cell.max.text=[[array objectAtIndex:indexPath.row] objectForKey:@"max"];
        Cell.forecast.text =[[array objectAtIndex:indexPath.row] objectForKey:@"forecast"];

        return Cell;    
    }

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

        return 80;
    }
4

1 に答える 1

2

これを試してみてください...役立つかもしれません...

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;   
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
      return [CommentsGetArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) 
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] ;
        //[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;



        commentsTextView = [[UITextView alloc]initWithFrame:CGRectMake(90, 4, 190, 50)];
        commentsTextView.delegate = self;
        commentsTextView.tag = 101;
        commentsTextView.textAlignment = UITextAlignmentLeft;

        [commentsTextView setScrollEnabled:YES];

        commentsTextView.backgroundColor =[UIColor clearColor];
        commentsTextView.font = [UIFont fontWithName:@"Arial" size:12.0];
        commentsTextView.textColor =[UIColor blackColor];
        commentsTextView.editable = NO;
        [cell addSubview:commentsTextView];



    }



     commentsTextView = (UITextView *)[cell viewWithTag:101];
    commentsTextView.text = [[CommentsGetArray objectAtIndex:indexPath.row]objectForKey:@"comment"];


    return cell;

}
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{

    return 70;
}

uitextView の代わりにラベルとして使用でき、データを表示するテキスト ビューまたはラベルをさらに作成できますが、フレームを変更することを忘れないでください。

于 2013-01-22T07:45:43.023 に答える