โอเค ฉันกำลังทำสิ่งนี้อยู่ มันไม่สมเหตุสมผลเลย ดังนั้นมันต้องเป็นแมลง หรือฉันทำผิดพลาดโง่ๆ บางอย่างลงไป
นี่คือสถานการณ์: ฉันมี UIViewController พร้อมไฟล์ xib มันมี UIView เชื่อมต่อกับคุณสมบัติมุมมอง UIImageView เชื่อมต่อกับคุณสมบัติที่เรียกว่า imageView และ UISegmentedControl เชื่อมต่อกับส่วนควบคุม
แต่ในโค้ดของฉัน ฉันไม่สามารถกำหนดรูปภาพให้กับมุมมองรูปภาพได้ เมื่อฉัน NSLog วัตถุ ฉันได้รับที่อยู่ 0x0 ดังนั้นจึงไม่มีการเชื่อมโยงเลย ฉันได้ตั้งค่าการเชื่อมโยงในตัวสร้างส่วนต่อประสานแล้ว ฉันได้รีสตาร์ท XCode และล้างและสร้างโปรเจ็กต์แล้ว ไม่มีอะไรทำงานและฉันเสียเวลาไปมากในการพยายามคิดออก ณ จุดนี้ ฉันยังได้ NSLoged วัตถุเซ็กเมนต์Control และได้รับ 0x0 เช่นกัน ดังนั้นจึงไม่มีสิ่งใดจาก XIB ที่เกี่ยวข้องกับโค้ด แต่ XIB เองกำลังโหลดเนื่องจากมีวัตถุแสดงบนหน้าจอ
ไม่มีใครมีความคิดใด ๆ เลยเกี่ยวกับสิ่งที่ฉันอาจพลาดไป? นี่เป็นเรื่องง่ายๆ ที่น่าหงุดหงิดอย่างยิ่งที่จู่ๆ ก็ปฏิเสธที่จะทำงาน
นี่คือโค้ดด้านล่างนี้ ในกรณีนี้ ฉันกำลังเข้าถึงอ็อบเจ็กต์ในตัวตั้งค่าสำหรับ projectId แต่ฉันก็ลองเข้าถึง imageView จากคลาสอื่นด้วย แต่มันก็ไม่ได้ผลเช่นกัน (และใช่ ฉันมีการประกาศ @property และสังเคราะห์สำหรับ imageView เมื่อฉันพยายาม)
DiagramViewController.h:
#import <UIKit/UIKit.h>
@interface DiagramViewController : UIViewController
{
NSUInteger projectId;
IBOutlet UIImageView *imageView;
IBOutlet UISegmentedControl *segmentControl;
}
@property NSUInteger projectId;
@end
DiagramViewController.m:
#import "DiagramViewController.h"
@implementation DiagramViewController
@synthesize projectId;
-(void)setProjectId:(NSUInteger)projId
{
NSLog(@"imageView: %@", imageView);
NSLog(@"segmentControl: %@", segmentControl);
projectId = projId;
NSString *filePath = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%i_schem", projectId] ofType:@"png" inDirectory:@"project-details/images/diagrams"];
NSData *imageData = [NSData dataWithContentsOfFile:filePath];
imageView.image = [UIImage imageWithData:imageData];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Overriden to allow any orientation.
return YES;
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
@end
และนี่คือรูปภาพการเชื่อมต่อของ Interface Builder:
-loadView
แต่ฉันต้องการเห็นโค้ดบางส่วนเพื่อให้เราสามารถตอบคำถามนี้ได้อย่างถูกต้อง - person jer   schedule 11.11.2010