iOS - "unrecognised selector sent to instance"错误,当名称标签
<p><p>当我将表格中的单元格按到另一个 View 时,我正在发送一些对象,这些对象必须显示该单元格的详细信息。</p>
<p>当我尝试更改标签(在第二个 View 上)文本时,我得到:</p>
<blockquote>
<p>Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '-:
unrecognized selector sent to instance 0x7f8e7ab5ed40'</p>
</blockquote>
<p>我的对象:</p>
<pre><code>@interface Item : NSObject
@property (strong,nonatomic) NSString * nameOfItem;
@property (strong,nonatomic) NSString * descriptionOfItem;
@property (strong,nonatomic) NSString * categoryOfItem;
-(instancetype)initItem:(NSString *)name category:(NSString *)category description:(NSString *)description;
-(NSComparisonResult)compare:(Item *)otherItem;
@end
</code></pre>
<p>我的手机:</p>
<pre><code>-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
NSMutableArray* sortedItems = [initWithArray:];
self.itemsTable.items = sortedItems;
listOfItems = ;
UITableViewCell *cell;
NSString *sectionTitle = [ objectAtIndex:indexPath.section];
cell = ;
NSInteger index = ;
cell.textLabel.text = ((Item *)[ objectAtIndex:index]).nameOfItem;
return cell;
}
</code></pre>
<p>我的行选择:</p>
<pre><code>-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSString *category = [ objectAtIndex:indexPath.section];//get category of selected item
Item *testItem = [ objectAtIndex:indexPath.row];
;
}
</code></pre>
<p>我为转会做准备:</p>
<pre><code>-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
...
if (){
if (]){
InfoViewController *fivc = (InfoViewController *)segue.destinationViewController;
fivc.gotchaItem = sender;
}
}
}
</code></pre>
<p>我的第二个观点:</p>
<pre><code>@interface InfoViewController ()
@property (weak, nonatomic) IBOutlet UILabel *nameOfFullInfoItem;
@property (weak, nonatomic) IBOutlet UILabel *categoryOfFullInfoItem;
@property (weak, nonatomic) IBOutlet UITextView *descriptionOfFullInfoItem;
@end
@implementation InfoViewController
- (void)viewDidLoad {
;
if (self.gotchaItem)
{
self.nameOfFullInfoItem.text = ;
self.categoryOfFullInfoItem.text = ;
self.descriptionOfFullInfoItem.text = ;
}
}
- (void)didReceiveMemoryWarning {
;
// Dispose of any resources that can be recreated.
}
@end
</code></pre>
<p>异常出现在行,这是我的第二个 View :</p>
<pre><code>#import "InfoViewController.h"
@interface InfoViewController ()
@property (weak, nonatomic) IBOutlet UILabel *nameOfFullInfoItem; //Here!
@property (weak, nonatomic) IBOutlet UILabel *categoryOfFullInfoItem;
@property (weak, nonatomic) IBOutlet UITextView *descriptionOfFullInfoItem;
@end
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>错误告诉您您正在对 <code>UITableViewCell</code> 调用 <code>nameOfItem</code> 方法。仅此一项就足够了,但您也有堆栈跟踪,追踪它应该不难。</p>
<p>在您附加的代码中,这是非常可疑的:</p>
<pre><code>cell.textLabel.text = ((Item *)[ objectAtIndex:index]).nameOfItem;
</code></pre>
<p>在该行设置断点并确保它是 <code>Item</code> 而不是 <code>UITableViewCell</code>。</p></p>
<p style="font-size: 20px;">关于iOS -"unrecognised selector sent to instance"错误,当名称标签,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/34360109/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/34360109/
</a>
</p>
页:
[1]