Ios 应用程序内和UITableView
这是我的密码:Ios 应用程序内和UITableView,ios,cocoa-touch,in-app-purchase,Ios,Cocoa Touch,In App Purchase,这是我的密码: - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (isPurchased == NO) { return [UITableviewExample c
- (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?我想在应用内购买成功后更改行。我的错误在哪里?谢谢。尝试为tableView调用reloadData-当您收到通知时,即表示已完成应用内购买
[tableView reloadData];
或使用动画:
[tableView reloadSections:0 withRowAnimation:UITableViewRowAnimationFade];
至少,对numberOfRowsInSection进行了两次明显的编辑,其中代码从未到达发布语句,但无论如何,您都不希望它到达发布语句,而CellForRowsInDexpath执行了不适当的发布语句,如果单元格成功出列,则会出现逻辑错误:
- (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;
}
在风格上,您显然也有变量UITableviewExample和UITableviewExample2,但作为一种良好的编程风格,变量名应该以小写字母开头,例如tableviewExample2和tableviewExample2
对于问题的实质,您需要向我们展示这些NSArray或NSMutableArray对象是如何初始化的。问题可能不在于上述代码,而在于这些数组的数量
但根据Guntis的出色观察,如果您的问题是在应用内购买后没有看到表发生更改,则可能需要重新加载数据。不要粗鲁,但您的代码很难理解您在做什么。这些UITableViewExample对象是什么,为什么要到处发布它们?你真的应该阅读并牢记苹果的Objective-C风格指南和内存管理指南。它将帮助您编写更标准化的代码,并帮助其他人更快地理解它。此外,您的文字解释不清楚,并且您没有提供关于应用内购买本身发生了什么的信息。出于这些原因,我不得不否决你的问题。另外,请阅读Xcode的标记wiki。这个问题与Xcode没有任何关系。