2013-08-02 2 views
0

보기에서 두 개의 tableview를 사용해야합니다. 또한 사용자 지정 셀을 사용하여 이러한 테이블을 만들어야합니다.2 사용자 정의 셀이 다른 UITableView

나는 뭔가를 시도했지만 테이블의 셀에서도 간단한 문자열을 볼 수 없었습니다.

여기에 무슨 문제가 있습니까?

내 업데이트 된 코드는 다음과 같습니다.

여전히 문제가 있습니다. 유효하지 않은 인수 예외가 있습니다. [LastVisitOrder superview] : 인식 할 수없는 선택기가 인스턴스로 전송되었습니다 .Uview 컨트롤러로 변경했습니다.

- (id)initWithFrame:(CGRect)frame 
{ 
self.view = [super initWithFrame:frame]; 

if (self) { 


    self.view.frame = CGRectMake(0, 0, 1024, 768); 


    [self.view setBackgroundColor:[[UIColor blackColor] colorWithAlphaComponent:0.8]]; 




    UIView *popup = [[UIView alloc]initWithFrame:CGRectMake((self.view.frame.size.width-860)/2,(self.view.frame.size.height-570)/2, 860, 570)]; 

    [popup setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"popup_bckgrnd"]]]; 

    [self.view addSubview:popup]; 


    UILabel *customerName = [[UILabel alloc]initWithFrame:CGRectMake(50, 50, 300, 30)]; 
    [customerName setBackgroundColor:[UIColor clearColor]]; 
    [customerName setText:@"Beşiktaş Eczanesi"]; 
    [customerName setFont:[UIFont fontWithName:@"Arial-BoldMT" size:18]]; 

    [popup addSubview:customerName]; 


    UILabel *customerDetail = [[UILabel alloc]initWithFrame:CGRectMake(50, 70, 300, 30)]; 
    [customerDetail setBackgroundColor:[UIColor clearColor]]; 
    [customerDetail setText:@"Tel: 231 213 23 23 Bla bla cad. Bla bla Sok. Bla bla Apt. No:Bla Blastan/Bistanbul"]; 
    [customerDetail setFont:[UIFont fontWithName:@"Arial" size:14]]; 

    [popup addSubview:customerDetail]; 


    UIButton *close = [[UIButton alloc]initWithFrame:CGRectMake(780, 65, 19, 19)]; 

    [close setBackgroundImage:[UIImage imageNamed:@"kapat"] forState:UIControlStateNormal]; 

    [close addTarget:self action:@selector(closePopUp:) forControlEvents:UIControlEventTouchUpInside]; 

    [popup addSubview:close]; 





    UIView *titleLine = [[UIView alloc]initWithFrame:CGRectMake(35, 100, 790, 2)]; 

    [titleLine setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"baslik_cizgi"]]]; 

    [popup addSubview:titleLine]; 


    dateTable = [[UITableView alloc]initWithFrame:CGRectMake(48.5, 165, 200, 345)]; 

    dateTable.layer.cornerRadius = 10; 

    [dateTable setBackgroundColor:[UIColor clearColor]]; 

    [popup addSubview:dateTable]; 

    dateTable.delegate=self; 

    dateTable.dataSource=self; 


    UIImageView *visitDatesLabel = [[UIImageView alloc]initWithFrame:CGRectMake(70, 122, 148, 30)]; 

    [visitDatesLabel setImage:[UIImage imageNamed:@"en_son_ziyaret"]]; 

    [popup addSubview:visitDatesLabel]; 

    UIImageView *line = [[UIImageView alloc]initWithFrame:CGRectMake(49.5, 160, 200, 2)]; 

    [line setImage:[UIImage imageNamed:@"ust_cizgi"]]; 

    [popup addSubview:line]; 

    UIImageView *line2 = [[UIImageView alloc]initWithFrame:CGRectMake(270.5, 160, 540, 2)]; 

    [line2 setImage:[UIImage imageNamed:@"ust_cizgi"]]; 

    [popup addSubview:line2]; 

    UIImageView *productsDatesLabel = [[UIImageView alloc]initWithFrame:CGRectMake(300, 122, 102, 29)]; 

    [productsDatesLabel setImage:[UIImage imageNamed:@"urunler"]]; 

    [popup addSubview:productsDatesLabel]; 

    UIImageView *verticalLine = [[UIImageView alloc]initWithFrame:CGRectMake(430, 115, 2, 45)]; 

    [verticalLine setImage:[UIImage imageNamed:@"dikey_cizgi"]]; 

    [popup addSubview:verticalLine]; 

    UILabel *firstMonth = [[UILabel alloc]initWithFrame:CGRectMake(455, 126, 148, 30)]; 

    [firstMonth setBackgroundColor:[UIColor clearColor]]; 

    [firstMonth setText:@"OCAK"]; 

    [firstMonth setFont:[UIFont fontWithName:@"Arial-BoldMT" size:12]]; 

    [firstMonth setTextColor:[UIColor grayColor]]; 

    [popup addSubview:firstMonth]; 


    UILabel *secondMonth = [[UILabel alloc]initWithFrame:CGRectMake(455+75, 126, 148, 30)]; 

    [secondMonth setBackgroundColor:[UIColor clearColor]]; 

    [secondMonth setText:@"ŞUBAT"]; 

    [secondMonth setFont:[UIFont fontWithName:@"Arial-BoldMT" size:12]]; 

    [secondMonth setTextColor:[UIColor grayColor]]; 

    [popup addSubview:secondMonth]; 

    UILabel *thirdMonth = [[UILabel alloc]initWithFrame:CGRectMake(455+75+75, 126, 148, 30)]; 

    [thirdMonth setBackgroundColor:[UIColor clearColor]]; 

    [thirdMonth setText:@"MART"]; 

    [thirdMonth setFont:[UIFont fontWithName:@"Arial-BoldMT" size:12]]; 

    [thirdMonth setTextColor:[UIColor grayColor]]; 

    [popup addSubview:thirdMonth]; 

    UILabel *rangeMonth = [[UILabel alloc]initWithFrame:CGRectMake(455+75+75+100, 126, 148, 30)]; 

    [rangeMonth setBackgroundColor:[UIColor clearColor]]; 

    [rangeMonth setText:@"OCAK-MART"]; 

    [rangeMonth setFont:[UIFont fontWithName:@"Arial-BoldMT" size:12]]; 

    [rangeMonth setTextColor:[UIColor grayColor]]; 

    [popup addSubview:rangeMonth]; 


    UIImageView *verticalLine2 = [[UIImageView alloc]initWithFrame:CGRectMake(510, 115, 2, 45)]; 

    [verticalLine2 setImage:[UIImage imageNamed:@"dikey_cizgi"]]; 

    [popup addSubview:verticalLine2]; 

    UIImageView *verticalLine3 = [[UIImageView alloc]initWithFrame:CGRectMake(590, 115, 2, 45)]; 

    [verticalLine3 setImage:[UIImage imageNamed:@"dikey_cizgi"]]; 

    [popup addSubview:verticalLine3]; 

    UIImageView *verticalLine4 = [[UIImageView alloc]initWithFrame:CGRectMake(670, 115, 2, 45)]; 

    [verticalLine4 setImage:[UIImage imageNamed:@"dikey_cizgi"]]; 

    [popup addSubview:verticalLine4]; 


    medSalesTable = [[UITableView alloc]initWithFrame:CGRectMake(270.5, 165, 540, 345)]; 

    medSalesTable.layer.cornerRadius = 10; 

    [medSalesTable setBackgroundColor:[UIColor clearColor]]; 


    [popup addSubview:medSalesTable]; 

    medSalesTable.delegate=self; 

    medSalesTable.dataSource=self;   
} 
return self; 
} 

-(void) closePopUp:(id)sender{ 

[self.view removeFromSuperview]; 

} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return 5;  
} 

-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
return 50; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

{ NSLog ("cellForRowAtIndexPath @");

if (tableView == dateTable) 
{ 
    static NSString *CellIdentifier = @"VisitDateCell"; 


    VisitDateCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (cell == nil) { 
     cell = [[VisitDateCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    } 

    [cell.lastVisit setText:@"fucker"]; 

    return cell; 
} 

else if(tableView == medSalesTable){ 
    static NSString *CellIdentifier2 = @"OrdersCell"; 


    OrdersCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier2]; 

    if (cell == nil) { 
     cell = [[OrdersCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier2]; 
    } 

    [cell.textLabel setText:@"fucker"]; 

    return cell; 
} 

} 
@end 
+0

하지만 난 cell.date.text – erdemgc

+1

으로 몇 가지가 첫 번째 LastVisitOrder가보기 것을되고, 그리고 뷰가 테이블에 대한 데이터 소스 안, 여기에 잘못이있다 "날짜"에 액세스 할 수 없습니다 보기 (당신은 데이터 소스를 설정했다고 가정합니다 - 당신입니까?). – rdelmar

+0

uiview 대신 uview 컨트롤러 여야합니까? – erdemgc

답변

0

사용 cell = [[[NSBundle mainBundle] loadNibNamed:@"VisitDateCell" owner:self options:nil] objectAtIndex:0];

대신

cell = [[[VisitDateCell alloc] initWithFrame:CGRectZero] autorelease]; 그런 cell.textLabel.text = @"YOUR_TEXT";

UPDATE를 사용! 당신의 변수 날짜에 대한 액세스 권한을 가지고 들어

당신은 VisitDateCell.h .Like에서 세계를 만들어야합니다 그런 다음 @property (nonatomic, strong) UILabel *date;

그것은 당신의 TableView 액세스 사용을 달성하기 위해 : (VisitDateCell*)cell.date = @"YOUR TEXT";

을 당신은 필요가 없습니다 커스텀 메소드 setText에서. cellForRows에서이 코드를 사용하십시오.

희망이 도움이 될 것입니다!

+0

을 업데이트했으나 아무런 차이점이 없다. 아무 것도 표에 나타나지 않는다. – erdemgc

+0

내 업데이트를 확인한다. – user2545330

+0

내 코드를 업데이트했다. – erdemgc

1

datasource 방법에서는 두 테이블을 구별해야합니다.

//cellForRowAtIndexPath 

if (tableView == medSalesTable) { 
    // configure the first table 
} 
else { 
    // configure the second table 
    // use a different cell identifier 
} 

당신은 또한 numberOfRowsInSection에서이 작업을 수행했는지 확인하고 numberOfSectionsInTableView 필요한 경우. 이 경우 테이블보기 datasource 속성을 모두 컨트롤러에 설정한다고 가정합니다.

0

이것은 내가 항상 사용하는 우아한 방법입니다. 여기에 배수 맞춤 세포를 만들 때만 작용합니다. 세포의 높이를 계산하는 코드는 없습니다.

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 

    /* 
     Call a function to create all custom cells. 
     Send the tableview and the indexPath to this function. 
     So, your code will be clean and easy to read an maintenance =D 
     DON'T forget to change the height of each cell 
    */ 
    if (indexPath.row < 3) 
     return [self createACustomCell1:tableView indexPath:indexPath]; 
    else 
     return [self createACustomCell2:tableView indexPath:indexPath]; 

} 


//************* 
// Create CUSTOM CELL 2 
//************* 
-(UITableViewCell *)createACustomCell1:(UITableView *)anTableView indexPath:(NSIndexPath *)indexPath{ 
    static NSString *CUSTOMCELL_1 = @"CUSTOMCELL_1"; 

    CustomCell_1 *cell = [anTableView dequeueReusableCellWithIdentifier:CUSTOMCELL_1]; 
    if (!cell){ 
    [anTableView registerNib:[UINib nibWithNibName:CUSTOMCELL_1 
              bundle:nil] forCellReuseIdentifier:CUSTOMCELL_1]; 
     cell = [anTableView dequeueReusableCellWithIdentifier:CUSTOMCELL_1]; 
    } 

    // Cell customization above 
    return cell; 
} 


//************* 
// Create CUSTOM CELL 2 
//************* 
-(UITableViewCell *)createACustomCell2:(UITableView *)anTableView indexPath:(NSIndexPath *)indexPath{ 
    static NSString *CUSTOMCELL_2 = @"CUSTOMCELL_2"; 

    CustomCell_2 *cell = [anTableView dequeueReusableCellWithIdentifier:CUSTOMCELL_2]; 
    if (!cell){ 
    [anTableView registerNib:[UINib nibWithNibName:CUSTOMCELL_2 
              bundle:nil] forCellReuseIdentifier:CUSTOMCELL_2]; 
     cell = [anTableView dequeueReusableCellWithIdentifier:CUSTOMCELL_2]; 
    } 

    // Cell customization above 


    return cell; 
} 
관련 문제