/ /
/ / LtsqViewController.m
/ / TianWei
/ /
/ / Created by newuser on 12-5-10.
/ / Copyright (c) 2012 年 __MyCompanyName__. All rights reserved.
/ /
# Import "LtsqViewController.h"
# Import "AsyncImageView.h"
# Import "FirstDetailViewController.h"
# Import "WebService.h"
# Import "Data.h"
@ Interface LtsqViewController ()
@ End
@ Implementation LtsqViewController
- (Void) viewWillAppear: (BOOL) animated {
/ / Self.navigationController.navigationBar.hidden = YES;
}
- (Id) initWithNibName: (NSString *) nibNameOrNil bundle: (NSBundle *) nibBundleOrNil
{
self = [super initWithNibName: nibNameOrNil bundle: nibBundleOrNil];
if (self) {
/ / Custom initialization
}
return self;
}
- (Void) viewDidLoad
{
self.navigationItem.title = @ "Forum Community";
self.view.backgroundColor = [UIColor whiteColor];
gjxwArray = [[NSMutableArray alloc] initWithCapacity: 0];
loading = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle: UIActivityIndicatorViewStyleGray];
loading.frame = CGRectMake (150, 170, 20, 20);
/ / ListViewLoading.hidesWhenStopped = YES;
loading.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
[Self.view addSubview: loading];
[Loading release];
[Loading startAnimating];
/ / Bottom Loading
homeTableView = [[UITableView alloc] initWithFrame: CGRectMake (0, 0, 320, 354)];
[HomeTableView setDelegate: self];
[HomeTableView setDataSource: self];
[Self.view addSubview: homeTableView];
[HomeTableView release];
page = 1;
NSString * urlParm = [NSString stringWithFormat: @ "news =% @ & command =% @ & page =% i", @ "new2", @ "2", page];
[[WebService instance] doHttpRequest: @ "http://192.168.131.73:8080/TianWei/data.do": urlParm];
[[NSNotificationCenter defaultCenter] addObserver: self selector: @ selector (update :) name: @ "newsUpdate" object: nil];
[Super viewDidLoad];
/ / Do any additional setup after loading the view.
}
- (Void) update: (NSNotification *) notification {
[[NSNotificationCenter defaultCenter] removeObserver: self name: notification.name object: nil];
Data * data = [notification object];
if ([data.listArray count]> 0) {
[GjxwArray removeLastObject];
}
for (NSDictionary * dic in data.listArray) {
List * list = [[List alloc] init];
[List setOid: [[dic valueForKey: @ "id"] intValue]];
[List setTime: [dic valueForKey: @ "time"]];
[List setTitle: [dic valueForKey: @ "title"]];
[List setImage: [dic valueForKey: @ "image"]];
[List setUrl: [dic valueForKey: @ "url"]];
[GjxwArray addObject: list];
[List release];
}
if ([data.listArray count]> = 10) {
List * l = [[List alloc] init];
[L setTitle: @ "more"];
[GjxwArray addObject: l];
[L release];
}
[HomeTableView reloadData];
}
/ / Select the Cell response to events
- (Void) tableView: (UITableView *) tableView didSelectRowAtIndexPath: (NSIndexPath *) indexPath {
List * list = [gjxwArray objectAtIndex: indexPath.row];
if ([list.title isEqualToString: @ "more"]) {
page = page +1;
NSString * urlParm = [NSString stringWithFormat: @ "news =% @ & command =% @ & page =% i", @ "new2", @ "2", page];
[[WebService instance] doHttpRequest: @ "http://server.bcjsw.com:8889/TianWei/data.do": urlParm];
[[NSNotificationCenter defaultCenter] addObserver: self selector: @ selector (update :) name: @ "newsUpdate" object: nil];
} Else {
FirstDetailViewController * firstDettaiView = [[[FirstDetailViewController alloc] init] autorelease];
firstDettaiView.oid = list.oid;
firstDettaiView.titleText = list.title;
firstDettaiView.url = list.url;
[Self.navigationController pushViewController: firstDettaiView animated: YES];
}
}
/ / Returns the number of rows
- (NSInteger) tableView: (UITableView *) tableView numberOfRowsInSection: (NSInteger) section {
return [gjxwArray count];
}
/ / Return View count
- (NSInteger) numberOfSectionsInTableView: (UITableView *) tableView {
return 1;
}
/ / Assemble each data
- (UITableViewCell *) tableView: (UITableView *) tableView cellForRowAtIndexPath: (NSIndexPath *) indexPath {
NSString * CellIdentifier = [NSString stringWithFormat: @ "Cell% d", indexPath.row];
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier: CellIdentifier] autorelease];
List * kainlist = [gjxwArray objectAtIndex: indexPath.row];
NSLog (@ "-------- = - title ---->% @", kainlist.title);
if ([[kainlist title] isEqualToString: @ "more"]) {
cell.textLabel.text = @ "Load More ...";
} Else {
List * list = [gjxwArray objectAtIndex: indexPath.row];
AsyncImageView * downImage = [[AsyncImageView alloc] initWithFrame: CGRectMake (10, 3, 50, 40)];
downImage.image = [UIImage imageNamed: @ "tianweiForum.jpg"];
[DownImage setImgUrl: list.image];
[Cell addSubview: downImage];
[DownImage release];
UILabel * title = [[UILabel alloc] initWithFrame: CGRectMake (80, 12, 203, 20)];
title.font = [UIFont systemFontOfSize: 16.0f];
title.text = list.title;
[Cell addSubview: title];
[Title release];
}
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
- (Void) viewDidUnload
{
[Super viewDidUnload];
/ / Release any retained subviews of the main view.
}
- (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@ End
Reply:
/ / Assemble each data
- (UITableViewCell *) tableView: (UITableView *) tableView cellForRowAtIndexPath: (NSIndexPath *) indexPath {
NSString * CellIdentifier = [NSString stringWithFormat: @ "Cell% d", indexPath.row];
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier: CellIdentifier] autorelease];
List * kainlist = [gjxwArray objectAtIndex: indexPath.row];
NSLog (@ "-------- = - title ---->% @", kainlist.title);
if ([[kainlist title] isEqualToString: @ "more"]) {
cell.textLabel.text = @ "Load More ...";
} Else {
List * list = [gjxwArray objectAtIndex: indexPath.row];
AsyncImageView * downImage = [[AsyncImageView alloc] initWithFrame: CGRectMake (10, 3, 50, 40)];
downImage.image = [UIImage imageNamed: @ "tianweiForum.jpg"];
[DownImage setImgUrl: list.image];
[Cell addSubview: downImage];
[DownImage release];
UILabel * title = [[UILabel alloc] initWithFrame: CGRectMake (80, 12, 203, 20)];
title.font = [UIFont systemFontOfSize: 16.0f];
title.text = list.title;
[Cell addSubview: title];
[Title release];
}
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
Changed
/ / Assemble each data
- (UITableViewCell *) tableView: (UITableView *) tableView cellForRowAtIndexPath: (NSIndexPath *) indexPath {
NSString * CellIdentifier = [NSString stringWithFormat: @ "Cell% d", indexPath.row];
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier: CellIdentifier] autorelease];
}
List * kainlist = [gjxwArray objectAtIndex: indexPath.row];
NSLog (@ "-------- = - title ---->% @", kainlist.title);
if ([[kainlist title] isEqualToString: @ "more"]) {
cell.textLabel.text = @ "Load More ...";
} Else {
List * list = [gjxwArray objectAtIndex: indexPath.row];
AsyncImageView * downImage = [[AsyncImageView alloc] initWithFrame: CGRectMake (10, 3, 50, 40)];
downImage.image = [UIImage imageNamed: @ "tianweiForum.jpg"];
[DownImage setImgUrl: list.image];
[Cell addSubview: downImage];
[DownImage release];
UILabel * title = [[UILabel alloc] initWithFrame: CGRectMake (80, 12, 203, 20)];
title.font = [UIFont systemFontOfSize: 16.0f];
title.text = list.title;
[Cell addSubview: title];
[Title release];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
Reply:
Your methods, but load more ... and the first data overlaps the second page, which is how it
Reply:
UITableViewCell reuse should still result.
You rephrased
NSString * CellIdentifier = [NSString stringWithFormat: @ "Cell% d", indexPath.row];
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier];
Changed
NSString * CellIdentifier = @ "CellIdentifier";
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier];
Try.
You can look online UITableViewCell reuse principle articles look, or see this
No comments:
Post a Comment