Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to reload data and refresh cell by tableView

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article shows you how tableView reloads data and refreshes cell. The content is concise and easy to understand, which will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

# import "NewTitleTableViewController.h"

@ interface NewTitleTableViewController ()

@ property (nonatomic,retain) NSArray * arr

@ property (nonatomic, retain) NSMutableData * data

@ end

@ implementation NewTitleTableViewController

-(void) dealloc

{

Self.data = nil

Self.arr = nil

[super dealloc]

}

-(id) initWithStyle: (UITableViewStyle) style

{

Self = [super initWithStyle:style]

If (self) {

}

Return self

}

-(void) viewDidLoad

{

[super viewDidLoad]

NSString * urlString = @ "http://XXXXX";

NSURL * url = [NSURL URLWithString:urlString]

NSMutableURLRequest * request = [NSMutableURLRequest requestWithURL:url]

NSString * parm = [NSString stringWithFormat:@ "% @", @ "? date=20131129&startRecord=10&len=30&udid=1234567890&terminalType=Iphone&cid=213"]

NSData * parmData = [parm dataUsingEncoding:NSUTF8StringEncoding]

/ / 6 set the request body

[request setHTTPBody:parmData]

/ / 7 set the request method

[request setHTTPMethod:@ "POST"]

Asynchronous POST

[NSURLConnection connectionWithRequest:request delegate:self]

}

Agent method:

-(void) connection: (NSURLConnection *) connection didReceiveResponse: (NSURLResponse *) response

{

Self.data = [NSMutableData data]

}

-(void) connection: (NSURLConnection *) connection didReceiveData: (NSData *) data

{

[self.data appendData:data]

}

-(void) connectionDidFinishLoading: (NSURLConnection *) connection

{

NSDictionary * dic = [NSJSONSerialization JSONObjectWithData:self.data options:NSJSONReadingMutableContainers error:nil]

Self.arr = dic [@ "news"]

[self.tableView reloadData]

}

-(void) connection: (NSURLConnection *) connection didFailWithError: (NSError *) error

{

}

TableView datadelegate method:

# pragma mark-Table view data source

-(NSInteger) numberOfSectionsInTableView: (UITableView *) tableView

{

Return 1

}

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

{

If (self.arr.count = = 0) {

Return 1

}

Return self.arr.count

}

Cell method

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

{

Static NSString * iden = @ "fff"

UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:iden]

If (! cell) {

Cell = [UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:iden] autorelease]

}

If (self.arr [indexPath.row] [@ "title"] = = nil)

{

Cell.textLabel.text = @ "loading...."

}

Else

{

Cell.textLabel.text = self.arr [indexPath.row] [@ "title"]

}

Return cell

}

The above is how tableView reloads data and refreshes cell. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report