我们为变量创建属性,以便在其他视图中使用它.我们对IBOutlets也一样.但并不总是使用它们.是否有必要为我们创建的每个IBOutlet创建属性我们的xib?或者这只是一个好习惯吗?
我创建了一个运行完美的ARC应用程序.它有一个UINavigationController,我用它来浏览视图,一切运行正常.
我正在将应用程序转换为iPad,我决定将其中一个视图显示为popover.(我不喜欢UIPopoverController所以我创建了自己的基本弹出窗口).它被添加到视图中如下..
MyViewController *hotelinf = [[MyViewController alloc]
initWithNibName:@"MyViewController_iPad" bundle:nil];
[self.view addSubview:hotelinf.view];
Run Code Online (Sandbox Code Playgroud)
该视图作为子视图添加正常.我正在添加的视图包含一个UIWebView,其中包含通常的委托方法,但是当视图尝试访问其中一个委托时,它只会崩溃.
*** -[MyViewController respondsToSelector:]: message sent to deallocated instance 0x7917b90
Run Code Online (Sandbox Code Playgroud)
具体来说,它崩溃在这条线上..
[self.webView loadHTMLString:stringResponse baseURL:nil];
Run Code Online (Sandbox Code Playgroud)
我已经多次将视图(和UINavigationControllers)显示为subViews而没有任何问题,尽管它们都没有包含UIWebView委托.我猜我必须设置我的UIViewController istance的委托,但我不知道如何.值得注意的是,如果我在现有的UINavigationController中推送视图,它会调用并加载HTML,这肯定意味着它与视图本身的代码无关.
任何帮助将不胜感激!这是代码(除了上面显示控制器)..
.H
@interface MyViewController : UIViewController <UIWebViewDelegate, UIActionSheetDelegate> {
//Unrelated IBOutlets
}
@property (nonatomic, strong) UIWebView *webView;
@end
Run Code Online (Sandbox Code Playgroud)
.M
@implementation MyViewController
@synthesize webView;
- (void)viewDidLoad
{
[super viewDidLoad];
self.webView = [[UIWebView alloc]initWithFrame:CGRectMake(317,283,393,354)];
self.webView.delegate = self;
[self.view addSubview:self.webView];
[NSThread detachNewThreadSelector:@selector(getHTMLString) toTarget:self withObject:nil];
}
-(void)getHTMLString {
@autoreleasepool {
//Download a valid HTML String
[self performSelectorOnMainThread:@selector(loadHTML) …Run Code Online (Sandbox Code Playgroud) 我正在调用UINavigationController并且通常允许它使用任何主要方向:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
// return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
BOOL isAllowed;
if ([allowedOrientations isEqualToString:@"portrait"]) {
isAllowed = (interfaceOrientation == UIInterfaceOrientationPortrait ||
interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
} else if ([allowedOrientations isEqualToString:@"landscape"]) {
isAllowed = (interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
interfaceOrientation == UIInterfaceOrientationLandscapeRight);
} else {
isAllowed = YES;
}
return isAllowed;
}
Run Code Online (Sandbox Code Playgroud)
从那里我调用UITableViewController:
myTable = [[SimpleDocViewerTable alloc] initWithFrame:thisFrame];
self = [super initWithRootViewController:myTable];
Run Code Online (Sandbox Code Playgroud)
哪里:
@interface SimpleDocViewerTable : UITableViewController {
Run Code Online (Sandbox Code Playgroud)
表视图控制器和导航控制器似乎大多正确集成.当我将新页面推到导航控制器上时,无论我使用哪个方向,它都会从右向左正确滚动:
SimpleDocPageVC *thisVC = [[SimpleDocPageVC alloc] initWithView:docView];
thisVC.title = …Run Code Online (Sandbox Code Playgroud) 我正在iPad上运行一个应用程序,将图像加载到旋转木马中.总共有138张图片.如果我将该数字减少到100,应用程序加载正常.然而,在138,应用程序暂停,而不是崩溃.
for正在到达viewDidLoad和第一个语句,如断点所示.问题出在第二个for声明中.
// loading images into the queue
loadImagesOperationQueue = [[NSOperationQueue alloc] init];
NSMutableArray *tmpArray = [[NSMutableArray alloc] initWithCapacity:14];
for (int i = 0; i < 137; i++) {
[tmpArray addObject:[NSString stringWithFormat:@"cover_%d.jpg", i]];
}
for (int i = 0; i < 137; i++) {
int index = arc4random() % [tmpArray count];
NSString *imageName = [tmpArray objectAtIndex:index];
[tmpArray removeObjectAtIndex:index];
[(AFOpenFlowView *)self.view setImage:[UIImage imageNamed:imageName] forIndex:i];
}
Run Code Online (Sandbox Code Playgroud)
我猜测存在内存问题,虽然因为我使用带有ARC的 iOS 5,所以我不应该进行任何手动内存管理.
可能是因为在记忆中存在太多东西吗?这是138张图片@~146 KB每张.这大概是20 MB,但我不认为仅此一项可能导致问题.
GDB退出时没有任何有用的输出,实际上根本没有输出.运行仪器显示,当暂停发生时,实际内存使用量仅为6.11 MB,77.4%CPU但175 MB虚拟内存.
我关心的是没有内存警告甚至实际崩溃的事实,线程只是暂停,无法自动恢复或终止,你必须从xcode中删除它.
iphone memory-management objective-c ios automatic-ref-counting
在我的iPhone应用程序中,我将我的uiwebview的委托设置为文件所有者,但它没有调用uiscrollviewdelegate方法
我的代码是
- (void)webViewDidStartLoad:(UIWebView *)webView{
NSLog(@"webViewDidStartLoad ");
}
- (void)webViewDidFinishLoad:(UIWebView *)webView{
NSLog(@"webViewDidFinishLoad ");
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
NSLog(@"scrollViewDidEndDecelerating ");
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
NSLog(@"scrollViewDidScroll ");
}
Run Code Online (Sandbox Code Playgroud)
但我得到了
webViewDidStartLoad
webViewDidFinishLoad
Run Code Online (Sandbox Code Playgroud)
控制台中的这些消息.
我是怎么了
提前致谢
我构建了一个简单的应用程序,用硬件激活一些东西,并不重要.
现在我只想让应用程序完全终止,如果用户离开屏幕,切换应用程序,接听电话,按主页按钮等.
我被所有应用程序状态混淆了,我找不到合适的地方来处理它.我想我需要听一个"进入睡眠"事件并发出终止命令(退出!)或类似的东西.
我有一个应用程序存储历史记录中的用户事件.事件将添加到一个控制器上,并显示在不同选项卡中的控制器中.
我想添加一个视觉确认信息,当用户点击"保存按钮"时,已记录事件.我正在考虑动画一个界面元素,以移动一个标签栏控制器,负责向用户显示记录.

为了做到这一点,我正在考虑动画我的一个界面元素的中心点.我知道如何设置中心点的动画,但它是直线的.如何以更"弯曲"的方式为中心点设置动画?有没有办法实现这个目标?
CGPoint center = self.ratingReticle.center;
[UIView animateWithDuration:0.6 delay:0 options:UIViewAnimationCurveEaseIn animations:^{
//move the element offscreen
self.ratingReticle.center = CGPointMake(260,500);
} completion:^(BOOL finished) {
//hide the interace element once it is offscreen
self.ratingReticle.alpha = 0;
//restore the position of the interface element
self.ratingReticle.center = center;
[ UIView animateWithDuration:0.4 animations:^{
//fade the element back at the original position
self.ratingReticle.alpha = 1;
} completion:^(BOOL finished) {
}];
}];
Run Code Online (Sandbox Code Playgroud) 我正在尝试做的是"导航"到一个更大的UIView,按钮和控件位于不同的地方.我把主UIView的尺寸比通常大两倍.它是640x480而不是320x480.
单击屏幕第一部分中的按钮后,我在x方向上进行了-320px的移动平移,以显示屏幕的第二个"隐藏"部分,其他功能将向用户显示.除了我无法让UIView回到原来的位置之外,一切都很完美.似乎我用来回到原始位置的按钮是320px的"超出界限",但是不起作用.
我的UIView被引用为"introScreen",以下是我调用的函数,用于通过x方向转换屏幕:
- (void)secondPartOfTheScreen {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.15];
introScreen.transform = CGAffineTransformMakeTranslation(-320, 0);
[UIView commitAnimations];
}
Run Code Online (Sandbox Code Playgroud)
调用此函数我的UIView正确移动,但当我的按钮出现在屏幕的这一部分时,它不会得到任何用户交互.如果我在屏幕的第一部分移动该按钮,它可以正常工作.它与屏幕边界有关?有可能解决它吗?
提前致谢!
信不信由你,我在问这个问题之前已经在互联网上搜索过了.令人难以置信的是,我还没有找到一个很好的明确示例,说明如何创建NSDictionaries的NSDictionary.
这是我到目前为止的代码,但它打印为null.有任何想法吗?
// Here I am creating the dictionaries in the code until I start getting them from the server ;)
NSArray *keys = [NSArray arrayWithObjects:@"mission", @"target", @"distance",@"status", nil];
NSArray *objectsA = [NSArray arrayWithObjects:@"tiger", @"bill", @"5.4km", @"unknown", nil];
NSDictionary *tiger = [NSDictionary dictionaryWithObjects:objectsA
forKeys:keys];
NSArray *objectsB = [NSArray arrayWithObjects:@"bull", @"roger", @"10.1km", @"you are dead", nil];
NSDictionary *bull = [NSDictionary dictionaryWithObjects:objectsB
forKeys:keys];
NSArray *objectsC = [NSArray arrayWithObjects:@"peacock", @"geoff", @"1.4km", @"target liquidated", nil];
NSDictionary *peacock = [NSDictionary dictionaryWithObjects:objectsC
forKeys:keys];
// …Run Code Online (Sandbox Code Playgroud) 我正在尝试为iOS 5构建一个动态库,但是没有这个模板.你能帮我吗?
ios ×10
iphone ×9
objective-c ×8
cocoa-touch ×3
uiview ×2
animation ×1
delegates ×1
dylib ×1
iboutlet ×1
ios5 ×1
ipad ×1
makefile ×1
nsdictionary ×1
screen ×1
uiscrollview ×1
uitableview ×1
uiwebview ×1
xcode ×1
xcode4.3 ×1