搜尋此網誌

顯示具有 UITableViewCell 標籤的文章。 顯示所有文章
顯示具有 UITableViewCell 標籤的文章。 顯示所有文章

2012年8月30日 星期四

UITableViewCell重復使用問題


由於發生 列表第一次登入可以產出
但是第二次登入卻無法呈現
才發現原來有這樣問題

解決方式
http://hi.baidu.com/suifeng_89/item/e026b7c2d39f2ab50c0a7b1f


iphone重用机制是苹果为了实现大量数据显示而采用的一种节省内存的机制,比如在UITableView和ScrollView 等地方。为什么要“可重用”???对于我们的项目来说,内存控制是必不可少的,如果一个tableview有几百个cell,这个内存消耗是很大的,而且有些cell里面都有image之类的很占内存的资源存在的话,那这样很容易出现memory warning甚至crash掉,这不是我们想要看到的。对此,tableview实现了它自己的管理方法dequeueReusableCellWithIdentifier(ps:我们在某些项目中scrollview来显示很多张image,在scrollview滑动中也要这样处理,来避免内存的过度消耗,只不过tableview它已经实现了这个方法,而不用我们自己去写)。
但是在实际使用过程中,会有以下问题:

2012年8月28日 星期二

客制化UITableViewCell


CustomerCell.h
#import <UIKit/UIKit.h>

@interface CustomerCell : UITableViewCell
@property (strong, nonatomic) IBOutlet UIImageView *filmImageView;
@property (strong, nonatomic) IBOutlet UILabel *filmNameLabel;
@property (strong, nonatomic) IBOutlet UILabel *instructorLabel;
@property (strong, nonatomic) IBOutlet UILabel *pointLabel;

@end

.m不變

2012年8月22日 星期三

UITableViewCell圖片固定大小

 float sw=50/cell.imageView.image.size.width;
  float sh=50/cell.imageView.image.size.height;
  cell.imageView.transform=CGAffineTransformMakeScale(sw,sh);

2012年7月26日 星期四

(IOS)動態調整 UITableViewCell 的高度

轉貼:http://gibuloto.com/blog/uitableviewcell-auto-height/


動態調整 UITableViewCell 的高度假設有一個這樣的 custom UITableViewCell:


因為評論的內容可能有好幾行,高度不一定,所以要做以下的處理:
in CommentCell.m

(IOS)tableView 自動加載 2

討論區:http://www.cocoachina.com/bbs/read.php?tid=59163&page=1

http://www.cocoachina.com/bbs/job.php?action=download&aid=33380好範例

(IOS)客制化UITableViewCell 2


UITableView的强大更多程度上来自于可以任意自定义UITableViewCell单元格。通常,UITableView中的Cell是动态的,在使用过程中,会创建一个Cell池,根据每个cell的高度(即tableView:heightForRowAtIndexPath:返回值),以及屏幕高度计算屏幕中可显示几个cell。而进行自定义TableViewCell无非是采用代码实现或采用IB编辑nib文件来实现两种方式,本文主要收集代码的方式实现各种cell自定义。

如何动态调整Cell高度

(IOS)客制化UITableViewCell


自定一個自已的UITableViewCell,於是在iCodeBlog找到了一篇文章"Custom UITableViewCell Using Interface Builder",上面還附有影片,可以很清楚的了解每一個步驟。


1.首先,我們先建立一個tableViewController和他的xib檔,並記得要設定section數量和列數量。
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return 10;
}

2.設定完成之後,新建一個Object-C class "yourStyleCell.m" ,subclass選項選UITableViewCell,並建立一個xib檔,
3.接下來我們使用Interface Builder,把原本的view刪除,從Library把UITableViewCell拉進來,並且設計自已想要的樣式,然後把這個xib檔的類別設定為"yourStyleCell"
4.接下來我們在"yourStyleCell"類別中建立所需要的IBOutlet並且和xib檔做link
5.最後我們回到tableViewController的.h檔中,import剛剛建立的"yourStyleCell.h"檔,
如果有變更cell的高度,請記得在tableViewController的table也要同樣變更row的高度

接下來我們要對下面這個function進行修改
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath {
static NSString *CellIdentifier = @"yourStyleCell";//這是我們在yourStyleCell.xib檔中對cell進行的定義值,
yourStyleCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
//初始化cell
if (cell == nil)
{
NSArray *nibObjs = [[NSBundle mainBundle] loadNibNamed:@"yourStyleCell" owner:nil options:nil];
for ( id currentObj in nibObjs)
{
if ([currentObj isKindOfClass:[ yourtStyleCell class]])
{
cell = ( yourStyleCell *)currentObj;
}
}
}
// 定義cell的內容
NSInteger row = [indexPath row];//get row number
// 如果是我們有一個Label,名稱為Name,我們可以這樣設定
[[cell Name] setText:@"Name"];
// 如果是我們有一個UIImageView,名稱為image,我們可以這樣設定
[[cell image] setImage:[UIImage imageNamed:@"yourImageFile.png"]];
return cell;
}


這裡有要注意的在建立yourStyleCell時候關聯要注意,影片中最後才發現哪裡錯了
另外如果要調整高度記得要調整TableView並不是針對tableViewCell