您的位置:首页 > 其它

三种方法绑定三列数据

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

觉得写得不错,帮忙打赏下,谢谢!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: