In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-24 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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.