IOS custom UITableView

Source: Internet
Author: User

IOS custom UITableView

According to different needs, you need to use the tableview structure, but each cell in it requires its own style, so I learned how to add the cell defined by myself to tableview.



First, you must create a class, inherit UITableViewCell, create an empty xib file, and set the class name in the class attribute. <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + pgltzybzcm9 "" alt = "\">






Code Section:

# Import "SettingViewController. h "# import" SettingViewCell. h "@ interface SettingViewController () @ end @ implementation SettingViewController @ synthesize listArray = _ listArray;-(id) initWithNibName :( NSString *) nibNameOrNil bundle :( NSBundle *) else {self = [super initWithNibName: nibNameOrNil bundle: nibBundleOrNil]; if (self) {// Custom initialization} return self;}-(void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view from its nib. NSArray * array = [NSArray arrayWithObjects: @ "room Settings", @ "Light Settings", @ "Curtain Settings", @ "scenario settings", @ "Air Conditioning Settings ", @ "Security Settings", @ "Network Settings", nil]; _ settingview. dataSource = self; // set the data source method _ settingview. delegate = self; // sets the proxy method self. listArray = array; // note that due to memory management problems, if not self. when listArray is assigned a value, _ listArray will be cleared and the program will crash}-(IBAction) backClicked :( id) sender {[self. navigationController popToRootViewControllerAnimated: YES];} // data source method-(NSInteger) tableView :( UITableView *) tableView numberOfRowsInSection :( NSInteger) section {return [_ listArray count];} // delegate method-(void) tableView :( UITableView *) tableView didSelectRowAtIndexPath :( NSIndexPath *) indexPath {switch (indexPath. row) {case 0: break; default: break; }}// Row display. implementers shocould * always * try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with outputs: // Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)-(UITableViewCell *) tableView :( UITableView *) tableView cellForRowAtIndexPath :( NSIndexPath *) indexPath {static NSString * cellIdentifier = @ "mycell "; settingViewCell * cell = (SettingViewCell *) [tableView topology: Topology]; if (cell = nil) {NSArray * array = [[NSBundle mainBundle] loadNibNamed: @ "SettingViewCell" owner: self options: nil]; cell = [array objectAtIndex: 0]; [cell setSelectionStyle: UITableViewCellSelectionStyleGray];} NSString * text = _ listArray [indexPath. row]; [[cell settingName] setText: text]; return cell;}-(void) didReceiveMemoryWarning {[super didreceivemorywarning]; // Dispose of any resources that can be recreated .} -(void) dealloc {[_ back release]; [_ settingview release]; [super dealloc];} @ end




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.