zoukankan      html  css  js  c++  java
  • 用NSDictionary填充自定义UITableView数据行

    .h文件

    @interface DetailsViewController : UITableViewController {    
        NSDictionary *dict;
    }
    
    @property (nonatomic, retain) NSDictionary *dict;
    

    .m文件代码 

    @implementation DetailsViewController
    @synthesize dict;
    

      

    - (void)viewDidLoad
    {
    	self.dict = [NSDictionary dictionaryWithObjectsAndKeys:
    				 @"Alfred", @"Name", 
    				 @"Chief Executive Officer", @"Title", 
    				 nil];	//[mydict release];
    
    	[super viewDidLoad];
    }
    
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        return [[dict allKeys] count];
    }
    

      

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *CellIdentifier = @"Cell";
        
        CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
    		cell = [nib objectAtIndex:0];
        }
    		
    	NSArray * sortedKeys = [[dict allKeys] sortedArrayUsingSelector: @selector(caseInsensitiveCompare:)];
        NSString * key = [sortedKeys objectAtIndex: indexPath.row];
        NSString * value = [dict objectForKey: key];
    
    	cell.name.text = key;
    	cell.value.text = value; 
        
    	//画竖线
    	UIView *lineView = [[[UIView alloc] initWithFrame:CGRectMake(80, 0, 1, cell.contentView.bounds.size.height)] autorelease];
    	lineView.backgroundColor = [UIColor grayColor];
    	[cell.contentView addSubview:lineView];
    	
        return cell;
    }
    


    签名:删除冗余的代码最开心,找不到删除的代码最痛苦!
  • 相关阅读:
    Android中的内部类引起的内存泄露
    Android的消息机制: Message/MessageQueue/Handler/Looper
    ArrayList/Vector的原理、线程安全和迭代Fail-Fast
    JVM中的Stack和Frame
    JVM中的垃圾收集算法和Heap分区简记
    无锁编程以及CAS
    简述Java内存模型的由来、概念及语义
    MQTT协议简记
    RabbitMQ的工作队列和路由
    RabbitMQ 入门
  • 原文地址:https://www.cnblogs.com/season2009/p/2544726.html
Copyright © 2011-2022 走看看