UITableView is the same as the ListView in Android, here first introduce a simple uitableview usage, because I also just learned. And some problems have been encountered. Go directly to the code.
This is ViewController.h.
#import <UIKit/UIKit.h> @interface Viewcontroller:uiviewcontroller<uitableviewdatasource, Uitableviewdelegate> @property (nonatomic,retain) nsarray * fileList; @property (nonatomic,retain) UITableView * TableView; @end
This is the viewcontroller.m file
#import "ViewController.h" @interface ViewController () @end @implementation viewcontroller- (void) viewdidload { [super viewdidload]; nsbundle * bundle = [nsbundle mainbundle]; nsstring * plistpath = [bundle pathforresource:@ "Infoheaderandtitleanddetile" ofType:@ "plist"]; self.fileList=[[NSArray alloc] initWithContentsOfFile:plistPath]; uitableview * tview = [[uitableview alloc] initwithframe:self.view.frame style:uitableviewstylegrouped]; tview.delegate =self; tview.datasource=self; _tableview=tview; [self.view addSubview:_tableView]; }- (void) didreceivememorywarning { [Super didreceivememorywarning]; // dispose of any resources that can be recreated.} -(uitableviewcell*) tableview: (uitableview *) Tableview cellforrowatindexpath: (NSIndexPath *) indexpath{ static nsstring *cellwithidentifier = @ "Cell"; uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier: cellwithidentifier]; if (Cell == nil) { cell = [[uitableviewcell alloc] initwithstyle: uitableviewcellstylesubtitle reuseidentifier:cellwithidentifier]; } & NBsp; nsuinteger row = [indexpath row]; nsdictionary * rowdict = [self.filelist objectatindex:row]; cell.textlabel.text = [rowdict objectforkey :@ "title"]; cell.imageview.opaque=yes;//must add this sentence,or the image will gone cell.imageview.image = [uiimage imagenamed:[[rowdict objectforkey :@ "Header"] stringbyappendingstring:@ ". jpg"]];//image must have the .jpg or other nslog (@ "%@", Cell.imageview); cell.detailtextlabel.text = [rowdict objectforkey :@ "Detail"]; Cell.accessorytype=uitableviewcellaccessorydisclosureindicator; return cell;} - (Nsinteger) TableView: (uitableview*) tableview nUmberofrowsinsection: (Nsinteger) section{ return [self.filelist count];} @end
There are three points to be aware of, and that's the problem I'm having.
1. Two protocol methods that must be implemented, equivalent to the abstract method of the Java interface
-(uitableviewcell*) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath
And
-(Nsinteger) TableView: (uitableview*) TableView numberofrowsinsection: (nsinteger) Section
2, the picture does not display correctly the reason
Cell.imageview.opaque=yes;//must Add this sentence,or the image would gone
This opaque property should be set to Yes, the default is no
3, the picture does not need to write the path, but the suffix name must write, for example. jpg,.png
This article is from the "spiritual Brother Notes" blog, please make sure to keep this source http://kinghacker.blog.51cto.com/7767090/1677432
iOS Development UITableView