gpt4 book ai didi

objective-c - 正在跳过详细 View Controller 中的第一个方法

转载 作者:行者123 更新时间:2023-11-29 13:24:08 25 4
gpt4 key购买 nike

在 RoomItem 中我需要什么重要的东西来确保不跳过这个方法吗?它是我的详细 View Controller 中的第一个,当我处于 Debug模式时它会不断被跳过。我确定我错过了一些非常简单的东西,但我已经盯着它看了好几个小时了,就是想不通它是什么。

@interface DetailViewController ()
- (void)configureView;
@end
@implementation DetailViewController
- (void)setDetailItem:(RoomItem *)newDetailItem
{
if (_detailItem != newDetailItem) {
_detailItem = newDetailItem;

// Update the view.
[self configureView];
}
}
- (void)configureView
{
// Update the user interface for the detail item.
if (self.detailItem) {
[_roomTxt setText:[_detailItem room]];
[_buildingTxt setText:[_detailItem building]];
[_dateTxt setText:[self dateCreatedString]];
[_buildingImageView setImage:[_detailItem buildingImage]];
_oi = [_detailItem objectIndex];
}
}

分配和初始化新的和现有的 detailViewController 的 MasterViewController(根 TableView )方法

- (void)insertNewObject:(id)sender
{
//add button invokes this
DetailViewController *ivc = [[DetailViewController alloc] init];
[self.navigationController pushViewController:ivc animated:YES];
NSLog(@"detailViewController allocated and initialized: %@", ivc);
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (!self.detailViewController) {
self.detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
NSLog(@"detailViewController initialized: %@", self.detailViewController);
}
//navigates to detailViewController and passes it the item's data
self.detailViewController.detailItem = [[[RoomList sharedStore] getAllItems] objectAtIndex:[indexPath row]];
[self.navigationController pushViewController:self.detailViewController animated:YES];
}

这里是 tableView:didSelectRowAtIndexPath 方法,它应该从 RoomList:sharedStore: 传递细节 View Controller 所需的一切:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (!self.detailViewController) {
self.detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
}
//navigates to detailViewController and passes it the item's data
self.detailViewController.detailItem = [[[RoomList sharedStore] getAllItems] objectAtIndex:[indexPath row]];
[self.navigationController pushViewController:self.detailViewController animated:YES];
}

...和 ​​RoomItem.m 文件:

- (void)awakeFromFetch
{
[super awakeFromFetch];

UIImage *pic = [UIImage imageWithData:[self buildingThumbnailData]];
[self setPrimitiveValue:pic forKey:@"buildingThumbnail"];
}
- (id)initWithRoom:(NSString *)room Building:(NSString *)building
{
self = [super init];
if (self) {
[self setRoom:room];
[self setBuilding:building];
}
return self;
}

DetailViewController.h

#import <UIKit/UIKit.h>
@class RoomItem;
//pic edit: added delegates
@interface DetailViewController : UIViewController <UINavigationControllerDelegate,
UIImagePickerControllerDelegate, UITextFieldDelegate, UIPopoverControllerDelegate,
UIPageViewControllerDelegate>
{
__weak IBOutlet UITextField *roomField;
__weak IBOutlet UITextField *buildingField;
__weak IBOutlet UILabel *dateLabel;

UIPopoverController *imagePickerPopover;
}
@property (nonatomic, strong) RoomItem *detailItem;
@property (weak, nonatomic) IBOutlet UIButton *updateBtn;
@property (weak, nonatomic) IBOutlet UIButton *detailsBtn;
@property (weak, nonatomic) IBOutlet UITextField *roomTxt;
@property (weak, nonatomic) IBOutlet UITextField *buildingTxt;
@property (weak, nonatomic) IBOutlet UILabel *dateTxt;
@property (weak, nonatomic) IBOutlet UIImageView *buildingImageView;
@property (weak, nonatomic) UIImage *buildingImage;
@property (weak, nonatomic) NSNumber *oi;
- (IBAction)backgroundTapped:(id)sender;
- (IBAction)takePicture:(id)sender;
- (IBAction)updateRoomItem:(id)sender;
- (IBAction)goToReportDetails:(id)sender;
@end

编辑:这是一个伪 UML 图,说明了我在调试器中单步执行时看到的内容(它从左到右,从上到下读取): enter image description here

最佳答案

很奇怪没有调用setter。我会接电话

self.detailViewController.detailItem = [[[RoomList sharedStore] getAllItems] objectAtIndex:[indexPath row]];

并将其替换为可能更容易理解的代码:

RoomItem *tempItem = [[[RoomList sharedStore] getAllItems] objectAtIndex:[indexPath row]];
DetailViewController *tempDVC = self.detailViewController; // could just use _detailViewController
tempDVC.detailItem = tempItem; // breakpoint on this line

然后当断点命中时,我将单步执行已编译的汇编程序以找出它的去向。 Xcode Debugger - how to single step at level of CPU instructions 上有相关说明- 特别是几周前 Max MacLeod 的回答。

我会把它写成另一条评论,因为它不是真正的答案,但它太长了!

关于objective-c - 正在跳过详细 View Controller 中的第一个方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13597612/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com