- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
编辑:此问题已移至 Getting an error from Xcode that is not on the internet related to index path因为这个问题已得到解决,但出现了新的错误。
我已经在这里呆了四天了!我在日志中没有收到任何错误,但是每当我单击填充有从 mysql 下载的动态数组的单元格时,它都不会转换。有趣的是,我在prepareForSegue中自己放置的nslogs没有得到任何响应...
ViewController.h
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
@interface ViewController : UIViewController<UITableViewDataSource,
CLLocationManagerDelegate,NSXMLParserDelegate, UISearchBarDelegate> {
IBOutlet UISearchBar *searchBar;
IBOutlet UITableView *tableView;
IBOutlet UILabel *Label;
CLLocationManager *locationManager;
NSMutableArray *coolarray;
float latitude;
float longitude;
}
@property (nonatomic, retain) CLLocationManager *locationManager;
@end
我已经排除了已解析的 xml 下载数据,但在我的实现文件中保留了下面 nsarray 的值
#import "ViewController.h"
#import "DetailViewController.h"
#import "Player.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)dealloc
{
[super dealloc];
[self.locationManager release];
if ( coolarray )
[coolarray release];
}
- (void)viewDidLoad
{
[super viewDidLoad];
coolarray = NULL;
self.locationManager = [[[CLLocationManager alloc] init] autorelease];
self.locationManager.delegate = self;
[self.locationManager startUpdatingLocation];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
// Table data delegate
- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section {
if ( coolarray != NULL ) {
return [coolarray count];
}
return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {
Player *cell = [tableView dequeueReusableCellWithIdentifier:@"Player"];
if (cell == nil)
{
cell = [[[Player alloc] initWithFrame:CGRectZero reuseIdentifier:@"Player"] autorelease];
}
NSDictionary *itemAtIndex = (NSDictionary *)[coolarray objectAtIndex:indexPath.row];
UILabel *nameLabel =[cell textLabel];
[nameLabel setText:[itemAtIndex objectForKey:@"name"]];
return cell;
}
- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {
Player *cell = [tableView dequeueReusableCellWithIdentifier:@"Player"];
if (cell == nil)
{
cell = [[[Player alloc] initWithFrame:CGRectZero reuseIdentifier:@"Player"] autorelease];
}
NSDictionary *itemAtIndex = (NSDictionary *)[coolarray objectAtIndex:indexPath.row];
UILabel *nameLabel =[cell textLabel];
[nameLabel setText:[itemAtIndex objectForKey:@"name"]];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *selectedLang = [coolarray objectAtIndex:indexPath.row];
DetailViewController *myDetViewCont = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:[NSBundle mainBundle]];
myDetViewCont.myDogLang = selectedLang;
[self performSegueWithIdentifier:@"showDogDetail" sender:nil];
[myDetViewCont release];
myDetViewCont = nil;
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"showDogDetail"])
{
DetailViewController *detailViewController =
[segue destinationViewController];
NSIndexPath *indexPath = [self.tableView
indexPathForSelectedRow];
NSString *dogLang = [self.coolarray objectAtIndex:indexPath.row];
detailViewController.myDogLang = dogLang;
}
}
@end
DetailViewController.h
#import <UIKit/UIKit.h>
@interface DetailViewController : UIViewController
{
IBOutlet UILabel *myLabel;
NSString *myDogLang;
}
@property (nonatomic, retain) IBOutlet UILabel *myLabel;
@property (nonatomic, retain) NSString *myDogLang;
@end
DetailViewController.m
#import "DetailViewController.h"
@interface DetailViewController ()
@end
@implementation DetailViewController
@synthesize myLabel;
@synthesize myDogLang;
- (void)viewDidLoad {
[super viewDidLoad];
myLabel.text = myDogLang;
self.myLabel.text = [self.myLabel objectAtIndex:0];
}
- (void)dealloc {
[myLabel release];
[myDogLang release];
[super dealloc];
}
我还添加了一张图片来显示我的连接:
最佳答案
看起来您在这里混合和匹配了几种不同的样式...我建议简化您的代码:
1) 删除表和详细 View 之间的当前segue。通过按住 Control 键并从原型(prototype)单元格(我假设这是一个原型(prototype)表)拖动到目标 View 来创建一个新单元格。不要忘记将标识符命名为与在prepareForSegue代码中使用的名称相同)。另外,如果您将 TableView Controller 嵌入到导航 Controller 中(这通常是可导航 TableView 中所期望的),则 segue 的样式应为“Push”。否则,样式应为“模态”(不过,根据应用程序的可用性,您可能需要重新考虑此方法)。
2) Player 类发生了什么?这是一个扩展 UITableViewCell 的类吗?当您单击 Storyboard中的原型(prototype)单元时,身份检查器中会列出什么类?是 Player 还是 UITableViewCell?属性检查器中单元格的标识符是什么?它是 Player 还是空白(根据您的代码,它需要是“Player”)?尝试将 Player 类(至少暂时)排除在外。保留单元格的标识符为 Player
,但在身份检查器中,将原型(prototype)单元格的自定义类设置为 UITableViewCell
。将您的 tableView:cellForRowAtIndexPath:
方法更改为:
- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Player"];
NSDictionary *itemAtIndex = (NSDictionary *)[self.coolarray objectAtIndex:indexPath.row];
cell.textLabel.text = [itemAtIndex objectForKey:@"name"];
return cell;
}
另外,这里还需要注意的是,您在此方法中指示了 CoolArray 的成员是 NSDictionary 类型。在prepareForSegue中,您将coolarray的成员视为NSString。他们不可能两者兼而有之。
3) 摆脱 tableView:didSelectRowAtIndexPath:
方法。这个很重要。这里有两种相互竞争的 Segue 方法。一个是在 Storyboard 和这个方法中设置的。按照现在编写代码的方式,单击单元格将调用prepareForSegue -> didSelect ->prepareForSegue。您尝试在此处执行的所有操作都可以在 prepareForSegue:
方法中完成(请参阅下一步)。
4)更改你的prepareForSegue:方法,使其看起来像这样(你甚至可以去掉“if”语句,因为你现在只有一个segue):
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"showDogDetail"])
{
DetailViewController *detailViewController =
[segue destinationViewController];
NSIndexPath *indexPath = [self.tableView
indexPathForSelectedRow];
NSString *dogLang = [self.coolarray objectAtIndex:indexPath.row];
// or if the array contains NSDictionaries, change the previous line to:
// NSString *dogLang = [[self.coolarray objectAtIndex:indexPath.row] objectForKey:@"name"];
detailViewController.myDogLang = dogLang;
}
}
5) 您的 DetailViewController 的 viewDidLoad 方法正在使用一些错误的代码覆盖标签文本(UILabel 不是数组)。将代码更改为:
- (void)viewDidLoad {
[super viewDidLoad];
self.myLabel.text = self.myDogLang;
}
鉴于我上面提到的一些概念问题,我强烈建议阅读 Apple's Table View Programming Guide 。它将帮助您理清生命周期和流程。
关于ios - UITableView 拒绝转到DetailViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13206030/
IO 设备如何知道属于它的内存中的值在memory mapped IO 中发生了变化? ? 例如,假设内存地址 0 专用于保存 VGA 设备的背景颜色。当我们更改 memory[0] 中的值时,VGA
我目前正在开发一个使用Facebook sdk登录(通过FBLoginView)的iOS应用。 一切正常,除了那些拥有较旧版本的facebook的人。 当他们按下“使用Facebook登录”按钮时,他
假设我有: this - is an - example - with some - dashesNSRange将使用`rangeOfString:@“-”拾取“-”的第一个实例,但是如果我只想要最后
Card.io SDK提供以下详细信息: 卡号,有效期,月份,年份,CVV和邮政编码。 如何从此SDK获取国家名称。 - (void)userDidProvideCreditCardInfo:(Car
iOS 应用程序如何从网络服务下载图片并在安装过程中将它们安装到用户的 iOS 设备上?可能吗? 最佳答案 您无法控制应用在用户设备上的安装,因此无法在安装过程中下载其他数据。 只需在安装后首次启动应
我曾经开发过一款企业版 iOS 产品,我们公司曾将其出售给大型企业,供他们的员工使用。 该应用程序通过 AppStore 提供,企业用户获得了公司特定的配置文件(包含应用程序配置文件)以启用他们有权使
我正在尝试将 Card.io SDK 集成到我的 iOS 应用程序中。我想为 CardIO ui 做一个简单的本地化,如更改取消按钮标题或“在此保留信用卡”提示文本。 我在 github 上找到了这个
我正在使用 CardIOView 和 CardIOViewDelegate 类,没有可以设置为 YES 的 BOOL 来扫描 collectCardholderName。我可以看到它在 CardIOP
我有一个集成了通话工具包的 voip 应用程序。每次我从我的 voip 应用程序调用时,都会在 native 电话应用程序中创建一个新的最近通话记录。我在 voip 应用程序中也有自定义联系人(电话应
iOS 应用程序如何知道应用程序打开时屏幕上是否已经有键盘?应用程序运行后,它可以接收键盘显示/隐藏通知。但是,如果应用程序在分屏模式下作为辅助应用程序打开,而主应用程序已经显示键盘,则辅助应用程序不
我在模拟器中收到以下错误: ImageIO: CGImageReadSessionGetCachedImageBlockData *** CGImageReadSessionGetCachedIm
如 Apple 文档所示,可以通过 EAAccessory Framework 与经过认证的配件(由 Apple 认证)进行通信。但是我有点困惑,因为一些帖子告诉我它也可以通过 CoreBluetoo
尽管现在的调试器已经很不错了,但有时找出应用程序中正在发生的事情的最好方法仍然是古老的 NSLog。当您连接到计算机时,这样做很容易; Xcode 会帮助弹出日志查看器面板,然后就可以了。当您不在办公
在我的 iOS 应用程序中,我定义了一些兴趣点。其中一些有一个 Kontakt.io 信标的名称,它绑定(bind)到一个特定的 PoI(我的意思是通常贴在信标标签上的名称)。现在我想在附近发现信标,
我正在为警报提示创建一个 trigger.io 插件。尝试从警报提示返回数据。这是我的代码: // Prompt + (void)show_prompt:(ForgeTask*)task{
您好,我是 Apple iOS 的新手。我阅读并搜索了很多关于推送通知的文章,但我没有发现任何关于 APNS 从 io4 到 ios 6 的新更新的信息。任何人都可以向我提供 APNS 如何在 ios
UITabBar 的高度似乎在 iOS 7 和 8/9/10/11 之间发生了变化。我发布这个问题是为了让其他人轻松找到答案。 那么:在 iPhone 和 iPad 上的 iOS 8/9/10/11
我想我可以针对不同的 iOS 版本使用不同的 Storyboard。 由于 UI 的差异,我将创建下一个 Storyboard: Main_iPhone.storyboard Main_iPad.st
我正在写一些东西,我将使用设备的 iTunes 库中的一部分音轨来覆盖 2 个视频的组合,例如: AVMutableComposition* mixComposition = [[AVMutableC
我创建了一个简单的 iOS 程序,可以顺利编译并在 iPad 模拟器上运行良好。当我告诉 XCode 4 使用我连接的 iPad 设备时,无法编译相同的程序。问题似乎是当我尝试使用附加的 iPad 时
我是一名优秀的程序员,十分优秀!