2014-02-06 5 views
0

당신이jQuery과 문제는

#import "ViewController.h" 
#import "DataService.h" 


@interface ViewController() 

@property (weak, nonatomic) IBOutlet UITableView *TableView; 
@property (strong, nonatomic) DataService *Service; 
@property (nonatomic, strong) MSTable *table; 
//@property (nonatomic, strong) MSClient *client; 
@property (nonatomic, strong) NSMutableArray *items; 

@end 

@implementation ViewController 

@synthesize Service; 
@synthesize rowitems; 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
    self.client = [MSClient clientWithApplicationURLString:@"https://outnight-mobile.azure-mobile.net/" 
              applicationKey:@"okYeRGfBagYrsbkaqWIRObeDtktjkF10"]; 
    self.table = [self.client tableWithName:@"notifications"]; 
    self.rowitems = [[NSMutableArray alloc] init]; 
    MSQuery *query = [self.table query]; 
    query.fetchLimit = 5; 
    [query readWithCompletion:^(NSArray *items, NSInteger totalCount, NSError *error) 
    { 
     //add the items to our local cop 
     self.rowitems = [items mutableCopy]; 


    }]; 
    [self.TableView reloadData]; 



} 


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView 
numberOfRowsInSection:(NSInteger)section { 
    //return 5; 
    NSLog(@"%d",[self.rowitems count]); 
    return 5; 


} 



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

     UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"]; 
     cell.textLabel.text = @"fool"; 
     return cell; 
} 


- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

@end 

UTTableView 데이터베이스에 가야 해주십시오 코드를 살펴 가질 수 계산 (인 미세 수행)하고 처음 5 개 행을 다시 검색해야하고한다. 하지만 내가

numberofrowsinsection 내가 배열 개수를 할 때 5의 금액을 볼 수 없습니다 ?? 이것은 나를 미치게하고있다, 내가 뭘 잘못하고 있니? 행 다음에
감사

+0

셀에 표시되는 내용은 무엇입니까? – ahmedalkaff

답변

1

이 코드를 가져온 된 이유입니다. 따라서이 호출이 완료되고 결과를 저장 한 후에 테이블을 다시로드해야합니다. 현재 테이블 뷰를 다시로드하면 self.rowitems 배열이 비어 있습니다.

블록 내에 reloadData을 호출하십시오.

[query readWithCompletion:^(NSArray *items, NSInteger totalCount, NSError *error) 
{ 
    //add the items to our local cop 
    self.rowitems = [items mutableCopy]; 

    [self.TableView reloadData]; 
}]; 
+0

똑같은 말을하려고했습니다. –

1

이동 : 완료 블록 즉에

[self.TableView reloadData]; 

:

다음
[query readWithCompletion:^(NSArray *items, NSInteger totalCount, NSError *error) 
    { 
     //add the items to our local cop 
     self.rowitems = [items mutableCopy]; 

     [self.TableView reloadData]; 
}]; 

이유는 : numberOfRowsInSection 처음 쿼리의 결과 호출됩니다 나중에 온다.

[query readWithCompletion:^(NSArray *items, NSInteger totalCount, NSError *error) 
{ 
    //add the items to our local cop 
    self.rowitems = [items mutableCopy]; 
}]; 

가 (푸른에) 비동기 네트워크 호출입니다 : 쿼리 결과 후 다시로드 테이블이

+0

감사하지만 움직이는 것은 나를 도왔다. – user3229170

+0

"totalCount"값을 확인 했습니까 ?? 그것이 0이 아닌지 확인하십시오 .. –

+0

화려한 남자 - 당신은 그날을 구했습니다! 그것은 결국 작동하지 않습니다. – user3229170