Objective c UIView之间的NSString转换
我想从一个Objective c UIView之间的NSString转换,objective-c,xcode,nsstring,Objective C,Xcode,Nsstring,我想从一个UIView在另一个UIView中使用NSString NSString *firstNameTemp = [[[[html componentsSeparatedByString:@"<first_name>"] objectAtIndex:1] componentsSeparatedByString:@"</first_name>"] objectAtIndex:0]; NSString *lastNameTemp = @"Михаил"; 在第一个u
UIView
在另一个UIView
中使用NSString
NSString *firstNameTemp = [[[[html componentsSeparatedByString:@"<first_name>"] objectAtIndex:1] componentsSeparatedByString:@"</first_name>"] objectAtIndex:0];
NSString *lastNameTemp = @"Михаил";
在第一个ui视图中创建NSString
有两种方法
NSString *firstNameTemp = [[[[html componentsSeparatedByString:@"<first_name>"] objectAtIndex:1] componentsSeparatedByString:@"</first_name>"] objectAtIndex:0];
NSString *lastNameTemp = @"Михаил";
编码有问题,但如果我用NSString
创建UILabel
,它会显示正确的字符串(Мааа)
在第二个ui视图中
如果使用方法
- (void) initPhotoViewWithFrame:(CGRect)frame Image:(UIImage *)image Name:(NSString *)name;
当我尝试使用firstNameTemp时,我得到一个错误
但是如果我使用lastnamtemp,则不会出现错误
问题是:如何成功地传递第一个NSString
(firstNameTemp)?这是一个内存管理错误。您必须保留firstNameTemp
(稍后再发布)。严格来说,lastNameTemp
也是如此,但是这个错误并没有出现,因为字符串文本(@“…”
)是由编译器创建的,并且在进程的生命周期内一直存在。当它在标签中显示正确的字符串时,然后将yourlable.text(它也是字符串)传递给另一个视图。这是最不可取的方式。因为在第一个UIView中,我只有UIWebView>>存在编码问题,但如果我使用NSString创建UILabel,它会显示正确的字符串(Мааа)看看我的问题——希望它能帮上忙!它起作用了!还有一个问题:我应该在initPhotoViewWithFrame方法中还是在first-UIView dealloc中释放它?