iOS Development UITableView

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.