2010-09-18 27 views
6

iPhone/iPad SimpleTableViewCells: Điều gì thay thế setText setImage không được chấp nhận trên các ô bảng?SimpleTableViewCells iPhone/iPad: Điều gì thay thế setText setImage không được chấp nhận trên các ô bảng?

Mã dưới đây đưa ra cảnh báo rằng setImage và setText không còn được dùng nữa. Vì vậy, những gì thay thế chúng? Cách tốt hơn mới để có được hành vi đơn giản này là gì?

 
static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier"; 
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier: SimpleTableIdentifier]; 

if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero 
     reuseIdentifier: SimpleTableIdentifier] autorelease]; 
} 
cell.image=[UIImage imageNamed:@"Wazoo.png"];; 
cell.text = @"Wazoo"; 

Vì vậy, cách đơn giản nhất để có ảnh hưởng như hình ảnh/văn bản của ô mà không làm nhiều việc hoặc nhận cảnh báo là gì?

+0

Bạn nên di chuyển * cell.imageView.image * dòng này trong if (tế bào == nil) {cell.imageView.image = [UIImage imageNamed: @ "wazoo. png "]; } để làm cho bảng của bạn xem nhanh. –

Trả lời

10

Với phiên bản mới của iOS SDK, setText và tài sản setImage đang bị phản đối và họ được thay thế bằng textLabel.text cho setText và imageView.image cho setImage ...
Với đặc tính mới này, mã của bạn sẽ được :

static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier"; 
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier: SimpleTableIdentifier]; 

if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero 
     reuseIdentifier: SimpleTableIdentifier] autorelease]; 
} 
cell.imageView.image = [UIImage imageNamed:@"Wazoo.png"];; 
cell.textLabel.text = @"Wazoo";

thuộc tính này thường được sử dụng khi các tế bào sử dụng phong cách preimpostated như UITableViewCellStyleDefault, UITableViewCellStyleSubtitle, UITableViewCellStyleValue1 và UITableViewCellStyleValue2 hoặc CGRect ...
Nếu bạn cũng sẽ hiển thị một tiểu tiêu đề, mã được sử dụng là:

cell.detailTextLabel.text = @"Your Subtitle Here!";
3

Bạn gọi textLabel.text và imageView.image trên ô.

static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier"; 
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier: SimpleTableIdentifier]; 

if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero 
     reuseIdentifier: SimpleTableIdentifier] autorelease]; 
} 
cell.imageView.image=[UIImage imageNamed:@"Wazoo.png"];; 
cell.textLabel.text = @"Wazoo"; 
Các vấn đề liên quan