-2

ここに画像の説明を入力ViewController.h

#import <UIKit/UIKit.h>

@interface TableViewController : UIViewController <UITableViewDataSource,UITableViewDelegate>
{
    UITableView *table;
    NSArray *tableData;
}
@end

ViewController.m

#import "TableViewController.h"

@interface TableViewController ()

@end

@implementation TableViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    table.delegate = self;
    table.dataSource = self;

    table = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] bounds] style:UITableViewCellStyleDefault];
    [self.view addSubview:table];


    tableData = [[NSArray alloc] initWithObjects:[UIImage imageNamed:@"StopWatch.png"],[UIImage imageNamed:@"TrashCan.png"],[UIImage imageNamed:@"Key.png"],[UIImage imageNamed:@"Telephone.png"],[UIImage imageNamed:@"ChalkBoard.png"],[UIImage imageNamed:@"Bucket.png"],nil];

}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [tableData count];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *simpleTableIdentifier = @"SimpleTableItem";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

    if (cell == nil)
    {
        //cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
    }

    cell.imageView.image = [tableData objectAtIndex:indexPath.row];
    return cell;
}

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

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    NSString *str = @"TableViewSection";
    return str;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 22;
}

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

@end

この画像をテーブルビューセルに表示したい。

テーブルビューのセルに画像を表示する方法を教えてください。

私のスタイルはコーディングのみです。私はストーリーボードを使用していません。

4

2 に答える 2

1

オブジェクトの初期化の前にdelegateおよびプロパティを割り当てている場合は、次のように順序を変更してみてください。dataSource

table = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] bounds] style:UITableViewCellStyleDefault];
table.delegate = self;
table.dataSource = self;
于 2012-12-14T08:59:26.180 に答える
0

あなたのデータソースは何ですか?xml テーブルビュー セル

このように static cell.imageView.image = [UIImage imageNamed:@"Maps-icon.png"]; cell.imageView.highlightedImage = [UIImage imageNamed:@"Maps-icon.png"]; また

[cell.imageView setImageWithURL:[NSURL URLWithString:[newsItem objectForKey:@"image"]]
               placeholderImage:[UIImage imageNamed:@"placeholder"]];

newsItem NSDictionary

NSDictionary *newsItem = [soapSource objectAtIndex:indexPath.row];

于 2012-12-14T09:42:06.117 に答える