三种方法绑定三列数据
2013-08-01 10:16
363 查看
---------------------------------------------------------------------------------------MyCell.h---------------------------------------------------------------------------------------
#import <UIKit/UIKit.h>
@interface MJCell :
UITableViewCell
@property (retain,
nonatomic) IBOutlet UILabel *firstLabel;
@property (retain,
nonatomic) IBOutlet UILabel *midLabel;
@property (retain,
nonatomic) IBOutlet UILabel *rightLabel;
- (void)setValue:(NSDictionary *)dic;
@end
---------------------------------------------------------------------------------------MyCell.m---------------------------------------------------------------------------------------
#import "MJCell.h"
@implementation MJCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super
initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selectedanimated:animated];
// Configure the view for the selected state
}
- (void)setValue:(NSDictionary *)dic{
_firstLabel.text=[dicobjectForKey:@"mc"];
_midLabel.text=[dicobjectForKey:@"jz"];
_rightLabel.text=[dicobjectForKey:@"ncount"];
}
- (void)dealloc {
[_firstLabel release];
[_midLabel release];
[_rightLabel release];
[super dealloc];
}
@end
--------------------------------------------------------------------------------------- jrkcViewController.h---------------------------------------------------------------------------------------
#import <UIKit/UIKit.h>
@interface jrkcViewController :UIViewController<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,retain)UITableView *tableView;
@property(nonatomic,retain)NSArray *listData;
@end
---------------------------------------------------------------------------------------jrkcViewController.m---------------------------------------------------------------------------------------
#import "jrkcViewController.h"
#import "ServiceHelper.h"
#import "SoapXmlParseHelper.h"
//#import "MJCell.h"
@interface jrkcViewController ()
@end
@implementation jrkcViewController
@synthesize tableView=_tableView;
@synthesize listData=_listData;
//@synthesize customCell;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super
initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
//获取今天的日期
-(NSString *)getDate{
NSDateFormatter*formatter = [[NSDateFormatteralloc]init];
[formatter setDateFormat:@"yyyyMMdd"];
NSString *locationString=[formatter
stringFromDate: [NSDate date]];
[formatter release];
return locationString;
}
- (void)viewDidLoad
{
[superviewDidLoad];
self.view.backgroundColor=[UIColorwhiteColor];
NSString *now=[selfgetDate];
UIBarButtonItem *leftbtn=[[UIBarButtonItemalloc]initWithTitle:@"back"style:UIBarButtonItemStyleDonetarget:selfaction:@selector(buttonBack)];
self.navigationItem.leftBarButtonItem=leftbtn;
[leftbtn release];
NSUserDefaults *user=[NSUserDefaultsstandardUserDefaults];
NSString *name=[user objectForKey:@"UserName"];
self.tableView=[[UITableViewalloc] initWithFrame:CGRectMake(0,30,self.view.bounds.size.width,self.view.bounds.size.height-30)];
self.tableView.dataSource=self;
self.tableView.delegate=self;
[self.view
addSubview:self.tableView];
//传递参数
NSMutableArray *params=[NSMutableArrayarray];
[params addObject:[NSDictionarydictionaryWithObjectsAndKeys:now,@"start_date",nil]];
[params addObject:[NSDictionarydictionaryWithObjectsAndKeys:now,@"end_date",nil]];
[params addObject:[NSDictionarydictionaryWithObjectsAndKeys:name,@"ygdm",nil]];
[params addObject:[NSDictionarydictionaryWithObjectsAndKeys:@"1",@"Flag",nil]];
//设置传递对象
ServiceArgs *args=[[[ServiceArgsalloc]init]autorelease];
args.methodName=@"SaleKClfxNEW";
args.soapParams=params;
//调用
self.listData=[NSArrayarray];
[[ServiceHelper sharedInstance]asynService:argscompleted:^(NSString *xml,NSDictionary *userInfo)
{
//NSLog(@"xml=%@\n",xml);
NSArray *arr=[SoapXmlParseHelpersearchNodeToArray:xmlnodeName:@"Table"];
self.listData=arr;
[self.tableViewreloadData];
NSLog(@"result===%@\n",arr);
} failed:^(NSError *error,NSDictionary *userInfo) {
NSLog(@"error=%@\n",[errordescription]);
}];
// Do any additional setup after loading the view from its nib.
}
- (void)buttonBack{
[selfdismissViewControllerAnimated:YEScompletion:nil];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [self.listDatacount];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellIdentifier=@"MJCell";
//MJCell *cell=[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
UITableViewCell *cell=[tableView
dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell==nil) {//UITableViewCellStyleValue1
/***
NSArray *arr=[[NSBundle mainBundle] loadNibNamed:@"MJCell" owner:self options:nil];
if ([arr count]>0) {
cell=[arr objectAtIndex:0];
NSLog(@"aa\n");
}else{
// cell=[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:cellIdentifier] autorelease];
}
**/
cell=[[[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:cellIdentifier]autorelease];
UILabel *label1=[[[UILabelalloc]initWithFrame:CGRectMake(0,0,100,44)]autorelease];
label1.tag=100;
label1.font=[UIFontsystemFontOfSize:8];
UILabel *label2=[[[UILabelalloc]initWithFrame:CGRectMake(100,0,100,44)]autorelease];
label2.tag=101;
UILabel *label3=[[[UILabelalloc]initWithFrame:CGRectMake(200,0,100,44)]autorelease];
label3.tag=102;
[cell.contentView
addSubview:label1];
[cell.contentView
addSubview:label2];
[cell.contentView
addSubview:label3];
}
NSDictionary *dic=[self.listDataobjectAtIndex:indexPath.row];
UILabel *label1=(UILabel*)[cellviewWithTag:100];
UILabel *label2=(UILabel*)[cellviewWithTag:101];
UILabel *label3=(UILabel*)[cellviewWithTag:102];
label1.text=[dic objectForKey:@"mc"];
label2.text=[dic objectForKey:@"jz"];
label3.text=[dic objectForKey:@"ncount"];
// cell.detailTextLabel.text=[dic objectForKey:@"jz"];
// cell.detailTextLabel.text=[dic obje=ctForKey:@"ncount"];
return cell;
}
- (void)didReceiveMemoryWarning
{
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)dealloc{
[super dealloc];
[_tableView release];
[_listData release];
// [customCell release];
}
@end
觉得写得不错,帮忙打赏下,谢谢!
#import <UIKit/UIKit.h>
@interface MJCell :
UITableViewCell
@property (retain,
nonatomic) IBOutlet UILabel *firstLabel;
@property (retain,
nonatomic) IBOutlet UILabel *midLabel;
@property (retain,
nonatomic) IBOutlet UILabel *rightLabel;
- (void)setValue:(NSDictionary *)dic;
@end
---------------------------------------------------------------------------------------MyCell.m---------------------------------------------------------------------------------------
#import "MJCell.h"
@implementation MJCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super
initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selectedanimated:animated];
// Configure the view for the selected state
}
- (void)setValue:(NSDictionary *)dic{
_firstLabel.text=[dicobjectForKey:@"mc"];
_midLabel.text=[dicobjectForKey:@"jz"];
_rightLabel.text=[dicobjectForKey:@"ncount"];
}
- (void)dealloc {
[_firstLabel release];
[_midLabel release];
[_rightLabel release];
[super dealloc];
}
@end
--------------------------------------------------------------------------------------- jrkcViewController.h---------------------------------------------------------------------------------------
#import <UIKit/UIKit.h>
@interface jrkcViewController :UIViewController<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,retain)UITableView *tableView;
@property(nonatomic,retain)NSArray *listData;
@end
---------------------------------------------------------------------------------------jrkcViewController.m---------------------------------------------------------------------------------------
#import "jrkcViewController.h"
#import "ServiceHelper.h"
#import "SoapXmlParseHelper.h"
//#import "MJCell.h"
@interface jrkcViewController ()
@end
@implementation jrkcViewController
@synthesize tableView=_tableView;
@synthesize listData=_listData;
//@synthesize customCell;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super
initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
//获取今天的日期
-(NSString *)getDate{
NSDateFormatter*formatter = [[NSDateFormatteralloc]init];
[formatter setDateFormat:@"yyyyMMdd"];
NSString *locationString=[formatter
stringFromDate: [NSDate date]];
[formatter release];
return locationString;
}
- (void)viewDidLoad
{
[superviewDidLoad];
self.view.backgroundColor=[UIColorwhiteColor];
NSString *now=[selfgetDate];
UIBarButtonItem *leftbtn=[[UIBarButtonItemalloc]initWithTitle:@"back"style:UIBarButtonItemStyleDonetarget:selfaction:@selector(buttonBack)];
self.navigationItem.leftBarButtonItem=leftbtn;
[leftbtn release];
NSUserDefaults *user=[NSUserDefaultsstandardUserDefaults];
NSString *name=[user objectForKey:@"UserName"];
self.tableView=[[UITableViewalloc] initWithFrame:CGRectMake(0,30,self.view.bounds.size.width,self.view.bounds.size.height-30)];
self.tableView.dataSource=self;
self.tableView.delegate=self;
[self.view
addSubview:self.tableView];
//传递参数
NSMutableArray *params=[NSMutableArrayarray];
[params addObject:[NSDictionarydictionaryWithObjectsAndKeys:now,@"start_date",nil]];
[params addObject:[NSDictionarydictionaryWithObjectsAndKeys:now,@"end_date",nil]];
[params addObject:[NSDictionarydictionaryWithObjectsAndKeys:name,@"ygdm",nil]];
[params addObject:[NSDictionarydictionaryWithObjectsAndKeys:@"1",@"Flag",nil]];
//设置传递对象
ServiceArgs *args=[[[ServiceArgsalloc]init]autorelease];
args.methodName=@"SaleKClfxNEW";
args.soapParams=params;
//调用
self.listData=[NSArrayarray];
[[ServiceHelper sharedInstance]asynService:argscompleted:^(NSString *xml,NSDictionary *userInfo)
{
//NSLog(@"xml=%@\n",xml);
NSArray *arr=[SoapXmlParseHelpersearchNodeToArray:xmlnodeName:@"Table"];
self.listData=arr;
[self.tableViewreloadData];
NSLog(@"result===%@\n",arr);
} failed:^(NSError *error,NSDictionary *userInfo) {
NSLog(@"error=%@\n",[errordescription]);
}];
// Do any additional setup after loading the view from its nib.
}
- (void)buttonBack{
[selfdismissViewControllerAnimated:YEScompletion:nil];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [self.listDatacount];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellIdentifier=@"MJCell";
//MJCell *cell=[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
UITableViewCell *cell=[tableView
dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell==nil) {//UITableViewCellStyleValue1
/***
NSArray *arr=[[NSBundle mainBundle] loadNibNamed:@"MJCell" owner:self options:nil];
if ([arr count]>0) {
cell=[arr objectAtIndex:0];
NSLog(@"aa\n");
}else{
// cell=[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:cellIdentifier] autorelease];
}
**/
cell=[[[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:cellIdentifier]autorelease];
UILabel *label1=[[[UILabelalloc]initWithFrame:CGRectMake(0,0,100,44)]autorelease];
label1.tag=100;
label1.font=[UIFontsystemFontOfSize:8];
UILabel *label2=[[[UILabelalloc]initWithFrame:CGRectMake(100,0,100,44)]autorelease];
label2.tag=101;
UILabel *label3=[[[UILabelalloc]initWithFrame:CGRectMake(200,0,100,44)]autorelease];
label3.tag=102;
[cell.contentView
addSubview:label1];
[cell.contentView
addSubview:label2];
[cell.contentView
addSubview:label3];
}
NSDictionary *dic=[self.listDataobjectAtIndex:indexPath.row];
UILabel *label1=(UILabel*)[cellviewWithTag:100];
UILabel *label2=(UILabel*)[cellviewWithTag:101];
UILabel *label3=(UILabel*)[cellviewWithTag:102];
label1.text=[dic objectForKey:@"mc"];
label2.text=[dic objectForKey:@"jz"];
label3.text=[dic objectForKey:@"ncount"];
// cell.detailTextLabel.text=[dic objectForKey:@"jz"];
// cell.detailTextLabel.text=[dic obje=ctForKey:@"ncount"];
return cell;
}
- (void)didReceiveMemoryWarning
{
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)dealloc{
[super dealloc];
[_tableView release];
[_listData release];
// [customCell release];
}
@end
觉得写得不错,帮忙打赏下,谢谢!
相关文章推荐
- Android ListView数据绑定显示的三种解决方法
- Android ListView数据绑定显示的三种解决方法
- ASP.NET MVC 中将数据从View传递到控制器中的三种方法(表单数据绑定)
- ASP.NET MVC 中将数据从View传递到控制器中的三种方法(表单数据绑定)
- ASP.NET MVC 中将数据从View传递到控制器中的三种方法(表单数据绑定)
- ASP.NET MVC 中将数据从View传递到控制器中的三种方法(表单数据绑定)
- ASP.NET MVC 中将数据从View传递到控制器中的三种方法(表单数据绑定)
- ASP.NET MVC 中将数据从View传递到控制器中的三种方法(表单数据绑定)
- 后台给GridView绑定数据时给每一行添加一个JS方法
- jQuery的三种bind/One/Live事件绑定使用方法
- 从数据库读取数据后将其输出成html标签的三种方法
- DropDownList的几种绑定数据方法
- Linq中使用反射实现--LINQ通用数据表绑定DataGrid控件的方法(原创)
- tensorflow载入数据的三种方式 之 TF生成数据的方法
- GridView绑定数据后想要更换每个单元格中内容的方法
- ASP.NET2.0中 TreeView 和ORACLE 数据绑定的一种方法
- 【Angular】数据绑定的方法
- php中使用Curl、socket、file_get_contents三种方法POST提交数据
- UWP开发:异步方法返回集合的数据绑定问题
- JavaScript中解析JSON数据的三种方法