iOS - 02

各个组件的简单学习:

slider的用法:

slider关联value change 事件

比如改变屏幕的背景色

 UISlider *slider = (UISlider*)sender;
   
 float v = slider.value + 0.2f;
 
 [self.view setBackgroundColor:[[UIColor alloc] initWithRed:0.2+v green:0.5+v blue:v alpha:0.8]];

webview的用法

webview用来加载网页内容

NSURL *url = [NSURL URLWithString:@"http://www.cnblogs.com/zhuqil/archive/2011/07/28/2119923.html"];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [self.webview loadRequest:request];

如果需要知道加载状态则需要实现UIWebviewDelegate协议

在使用的时候需要[self.webview setDelegate:self];设置该协议的代理,之前由于没有设置,导致以下几个方法没有运行:

-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
    
}

-(void)webViewDidStartLoad:(UIWebView *)webView{
    self.acIndicator.hidden = NO; //UIActivityIndicatorView的使用,属性可见与不可见
    [self.acIndicator startAnimating];//UIActivityIndicatorView的动画,start启动动画则转,stop为停止动画
    NSLog(@"startload");
}

-(void)webViewDidFinishLoad:(UIWebView *)webView{
    [self.acIndicator stopAnimating];
    self.acIndicator.hidden = YES;
    NSLog(@"finishload");
}


tableview的使用

最简单的使用,接口继承UITableViewDelegate和UITableViewDataSource两个协议

在viewDidLoad方法设置代理和数据源,

至少需要实现的方法是:

//返回这个section的行数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [arr count];
}

//定制每行怎么显示
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString * identifier = @"tableviewIdentifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if(cell == nil){
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    NSUInteger row = [indexPath row];
    cell.textLabel.text = [arr objectAtIndex:row];
    return cell;
    
}

数据用NSMutableArray就可以了

自定义TableViewCell的学习

创建一个Objective-C文件继承自UITableViewCell

再创建一个empty xib文件,向里面拖入UITableViewCell  和要显示的元素,并将xib与.h文件关联

然后在

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString * identifier = @"tableviewIdentifier";
    static BOOL nibRegistered = NO;
    if(!nibRegistered){
        UINib *nib = [UINib nibWithNibName:@"CustomCell" bundle:nil];
        [tableView registerNib:nib forCellReuseIdentifier:identifier];
        nibRegistered = YES;
    }
    CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    NSInteger row = [indexPath row];
    NSDictionary *dict = [dataList objectAtIndex:row];
    cell.name  = [dict objectForKey:@"name"];
    cell.dec = [dict objectForKey:@"dec"];
    cell.loc = [dict objectForKey:@"loc"];
    cell.image = [imageList objectAtIndex:row];

return cell

}


又犯了一个低级错误

NSMutableArray 没有初始化就往里面addObject最后在列表中查不到数据,太初心大意了!





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值