2012-09-01 14 views
-4

這裏是我的代碼:在App和UITableView的

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

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    if (isPurchased == NO) { 

     return [UITableviewExample count]; 
     [UITableviewExample release]; 
    } 
    else 
    { 
     return [UITableviewExample2 count]; 
     [UITableviewExample2 release]; 
    } 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 

     if (isPurchased == NO) { 

      cell.textLabel.text = [UITableviewExample objectAtIndex:indexPath.row]; 
      [UITableviewExample release]; 
     } 
     else { 
      cell.textLabel.text = [UITableviewExample2 objectAtIndex:indexPath.row]; 
      [UITableviewExample2 release]; 

     } 
    } 

    return cell; 
} 

誰能幫幫我好嗎?成功購買應用程序後,無需更改。如果我用

-(IBAction)test 
{ 
    if (isPurchased == yes) { 
     buyButton.hidden = yes; 
    } 
} 

很好用。我嘗試了兩種應用程序,應用程序內購買,一切都很好,即使我用於隱藏,更改標籤文本,它的工作原理,我如何使用UITableView在應用程序內購買?我想在成功購買應用程序後更改行。我的錯誤在哪裏?謝謝。

+3

不要粗魯,但你的代碼很難理解你在做什麼。這些「UITableViewExample」對象是什麼,你爲什麼將它們釋放到任何地方?你真的應該閱讀並理解Apple的Objective-C風格指南和內存管理指南。它將幫助您編寫更多標準化的代碼,並幫助他人更快地理解它。此外,您的文字說明還不清楚,您也沒有提供關於應用內購買本身發生情況的信息。由於這些原因,我必須降低你的問題。 –

+0

另外,請閱讀Xcode的標籤wiki。這個問題與Xcode沒有任何關係。 – 2012-09-01 06:43:38

回答

1

最起碼,一對夫婦明顯的編輯到numberOfRowsInSection(其中代碼永遠不會到達release語句,但你不會是想,反正)和cellForRowAtIndexPath(你在哪裏執行不當release報表,有一個邏輯錯誤,如果電池是有史以來成功出隊):

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    if (isPurchased == NO) { 
     return [UITableviewExample count]; 
     // [UITableviewExample release]; 
    } 
    else 
    { 
     return [UITableviewExample2 count]; 
     // [UITableviewExample2 release]; 
    } 

} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    } 

    // this was in the above "if (cell == nil)" block, but should be outside of it 

    if (isPurchased == NO) { 
     cell.textLabel.text = [UITableviewExample objectAtIndex:indexPath.row]; 
     // [UITableviewExample release]; 
    } 
    else { 
     cell.textLabel.text = [UITableviewExample2 objectAtIndex:indexPath.row]; 
     // [UITableviewExample2 release]; 
    } 

    return cell; 
} 

在風格上,你顯然也有變量UITableviewExampleUITableviewExample2,但是作爲一種很好的編程風格,變量名應該以小寫字母開頭,例如, tableviewExampletableviewExample2

對於您的問題的實質,您需要告訴我們這些NSArray(或NSMutableArray)對象是如何初始化的。這個問題可能不在上面的代碼中,而是在這些數組的人口中。

但是,對於Guntis的出色觀察,如果您的問題是在應用程序購買之後沒有看到表格更改,則可能需要執行reloadData

1

嘗試爲tableView調用reloadData - 當您收到通知時,該應用內購買已完成。

[tableView reloadData]; 

或與動畫:

[tableView reloadSections:0 withRowAnimation:UITableViewRowAnimationFade];