2011-02-18 7 views
0

안녕하세요, 다음 코드는 UIAlertTableView에서 UIAlertView를 서브 클래 싱 한 UITableView에 UITableView를 추가하려고합니다.테이블 뷰에 데이터를로드하는 방법

#import "UIAlertTableView.h" 

#define kTablePadding 8.0f 


@interface UIAlertView (private) 
- (void)layoutAnimated:(BOOL)fp8; 
@end 

@implementation UIAlertTableView 

@synthesize dataSource; 
@synthesize tableDelegate; 
@synthesize tableHeight; 
@synthesize tableView; 

- (void)layoutAnimated:(BOOL)fp8 { 
    [super layoutAnimated:fp8]; 
    [self setFrame:CGRectMake(self.frame.origin.x, self.frame.origin.y - tableExtHeight/2, self.frame.size.width, self.frame.size.height + tableExtHeight)]; 

    // We get the lowest non-control view (i.e. Labels) so we can place the table view just below 
    UIView *lowestView; 
    int i = 0; 
    while (![[self.subviews objectAtIndex:i] isKindOfClass:[UIControl class]]) { 
     lowestView = [self.subviews objectAtIndex:i]; 
     i++; 
    } 

    CGFloat tableWidth = 262.0f; 

    tableView.frame = CGRectMake(11.0f, lowestView.frame.origin.y + lowestView.frame.size.height + 2 * kTablePadding, tableWidth, tableHeight); 

    for (UIView *sv in self.subviews) { 
     // Move all Controls down 
     if ([sv isKindOfClass:[UIControl class]]) { 
      sv.frame = CGRectMake(sv.frame.origin.x, sv.frame.origin.y + tableExtHeight, sv.frame.size.width, sv.frame.size.height); 
     } 
    } 

} 

- (void)show{ 
    [self prepare]; 
    [self.tableView reloadData]; 
    [super show]; 
} 

- (void)prepare { 
    if (tableHeight == 0) { 
     tableHeight = 150.0f; 
    } 

    tableExtHeight = tableHeight + 2 * kTablePadding; 

    tableView = [[UITableView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 0.0f, 0.0f) style:UITableViewStyleGrouped]; 
    tableView.delegate = tableDelegate; 
    tableView.dataSource = dataSource;  

    [self insertSubview:tableView atIndex:0]; 

    [self setNeedsLayout]; 
} 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    return nil; 
} 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ 
    return 10; 
} 
- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
} 
- (void)dealloc { 
    [tableView release]; 
    [super dealloc]; 
} 
@end 

Now i want to load this tableView from data by calling reloadData in 'show' method but it is not calling delegate methods written in the class. 

Also, i am showing the code of other class from where i am showing the alert. 

- (void) showEsign{ 
    //IRPSaveRepairResponseDO *saveRepairDO = [[[[IRPSessionCache sharedInstance] currentSessionObject] dataModel] saveRepairDetails]; 
    IRPDataModel *dataModel = [[[IRPSessionCache sharedInstance] currentSessionObject] dataModel]; 
    IRPProductDetailsDO *prodDO = [dataModel productDetailsDO]; 
    //IRMLegalDocumentDO *legalDocDO = [dataModel legalDocDO]; 

    NSMutableArray *printLanguageArray = [prodDO languageOptionsDisplayArray]; 

    if ([printLanguageArray count] == 1) { 
     DLog(@"prodDO.defaultLanguageDescription: %@", prodDO.defaultLanguage); 
     [prodDO setUserSelectedLanguageForEsign:prodDO.defaultLanguage]; 
     UIAlertTableView *alert = [[UIAlertTableView alloc] initWithTitle:@"Select language" 
                    message:@"Concierge" 
                   delegate:self 
                 cancelButtonTitle:kCancel 
                 otherButtonTitles:kNext, nil]; 
     alert.tableDelegate = self; 
     alert.dataSource = self; 
     alert.tableHeight = 120;  
     [alert.tableView reloadData]; 
     [alert show]; 
    } 
} 

하나의 배열로이 tableView를로드하려고합니다.

+2

그래서 당신이 직면하고있는 문제는 무엇입니까? – Robin

+3

IMHO 알림보기에 테이블을 넣는 것은 좋은 사용자 환경이 아닙니다. – Eimantas

답변

0

이것은 내 머리를 아프게합니다.

테이블 뷰 초기화 위치를 잘 모르겠습니다. 아마도 UIAlertView 하위 클래스 외부에있을 것입니다. 내 추측은 delegat/datasource가 propetly로 설정되어 있지 않습니다. 다음과 같은 내용을 추가 할 수도 있습니다.

그러나 나는 다시 술에 취해서 내가 이해하지 못하면 미안해.

관련 문제