我有一个MKAnnotationView(draggable属性设置为YES)自定义图像,通过image属性设置.将注释添加到地图时,它具有自定义图像.但拖动注释时图像会返回默认引脚.image每次dragState改变时我都试图覆盖这个属性.这里也没有运气.
我开始在iOS中使用OpenGL.我总是学会用OpenGL绘制东西glBegin(),glEnd()所以这对我来说是一种新的东西.
我想画一个简单的三角形.我可以很好地绘制一个白色三角形,我甚至可以使用绘制整个彩色三角形glColor.但每当我尝试使用下面的代码为每个顶点指定颜色EXC_BAD_ACCESS时,我会在绘制数组时得到一个颜色.我正在使用iOS 4.3模拟器.我究竟做错了什么?
- (void) render:(CADisplayLink*)displayLink {
glClearColor(0, 104.0/255.0, 55.0/255.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
GLfloat vertices [] = {0,0,0, 0,100,0, 100,0,0};
GLfloat colours [] = {1.0,1.0,1.0, 1.0,1.0,1.0, 1.0,1.0,1.0};
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vertices);
glColorPointer(3, GL_FLOAT, 0, colours);
glDrawArrays(GL_TRIANGLES, 0, 3); <-- CRASHES HERE
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
[self.context presentRenderbuffer:GL_RENDERBUFFER];
}
Run Code Online (Sandbox Code Playgroud) 我想知道问题主题的变量声明是否合法.想象一下以下代码:
__weak typeof(self) weakSelf = self;
[self doSomethingThatMayCauseRetainCycleWithBlock:^{
typeof(self) self = weakSelf; // <---- !!!!
if (self == nil) return;
NSAssert(self.someProperty != nil, @"This doesn't lead to retain cycle!");
[self doSomething];
self.someProperty = someValue;
// even
self->someIvar = anotherValue;
}
Run Code Online (Sandbox Code Playgroud)
此代码在Xcode 4.5.2中完美运行,仅发出警告Declaration shadows a local variable.
这个怪癖有什么意义:
self为弱变量的强引用后,您可以安全地复制/移动块内部/外部的代码,而不会有偶尔创建保留周期的风险(除了ivars,但它们是邪恶的).NSAssert 块中不再导致保留周期.更新
我发现这种技术libextobjc用于@weakify/@strongify宏.
例如,如果我要求a UITableView显示在视图中的其他内容下方,那么最佳做法是:
UITableView作为子视图,或UITableViewController?据我所知,两者都会提供相同的用户体验,但我有兴趣知道哪种方法被认为是最佳实践?
我正在尝试将数据直接加载到UIWebView:
[webView loadData:data MIMEType:@"text/html" textEncodingName:@"utf-8"
baseURL:nil];
Run Code Online (Sandbox Code Playgroud)
数据是一些html字符串,其中包含一些外部链接。我试图基于UIWebView属性启用后退和前进按钮:
self.forwardBtn.enabled = self.webView.canGoForward;
self.backBtn.enabled = self.webView.canGoBack;
Run Code Online (Sandbox Code Playgroud)
但是,即使在初始加载后我在Web视图中单击了不同的链接后,webView.canGoForward和webView.canGoBack也总是返回NO。
有什么想法吗?
我有一个UITableView并且想要动画再次出现的行.我也想在动画之间切换,有些小区应该得到UITableViewRowAnimationLeft和其他人一样UITableViewRowAnimationRight.但我不知道如何用我的实现这个功能UITableViewController.我尝试将以下代码行插入cellForRowAtIndexPath:
[self.tableView beginUpdates];
NSArray *updatePath = [NSArray arrayWithObject:indexPath];
[self.tableView reloadRowsAtIndexPaths:updatePath
withRowAnimation:UITableViewRowAnimationLeft];
[self.tableView endUpdates];
Run Code Online (Sandbox Code Playgroud)
细胞的顺序改变了,或者其中一些出现了两次,而不是在细胞中滑动.我还尝试在创建单元格后插入这些行.
if (cell == nil) {
...
} else {
[self.tableView beginUpdates];
NSArray *updatePath = [NSArray arrayWithObject:indexPath];
[self.tableView reloadRowsAtIndexPaths:updatePath
withRowAnimation:UITableViewRowAnimationLeft];
[self.tableView endUpdates];
Run Code Online (Sandbox Code Playgroud) 我有两难,我有两个UIPickerViews,当两个不同的视图加载时"显示".我从一开始就UIPickerView通过加载数组和UIPickerViewViewController中的所有其他操作来启动并运行.
我认为这就像复制/粘贴新的相同方法一样简单UIPickerView,但只是更改变量名称,也在同一个中UIViewController.
问题是 - 两者UIPickerView都在下拉列表中显示相同的数据集?我只是遗漏了一些明显的东西吗?
更新如下
我为下面的所有四种方法做了这个,现在应用程序在加载"下一个"视图后崩溃了?这看起来不错吗?
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView
- (NSInteger)thePickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component
- (NSString *)thePickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
- (void)thePickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
Run Code Online (Sandbox Code Playgroud) 每当我暂停游戏时我都会遇到严重的问题,因为我的大部分时间performSelector:都有延迟,所以它不会立即执行,但如果我暂停游戏那么事情就会变坏然后performSelector仍在调用...我应该如何克服这个问题?
我知道有一个功能NSObject可以取消所有请求,但这并不是我正在寻找的,因为我希望该方法在玩家恢复游戏时继续执行.
调用函数时我有bug dynamic_arr- 不知怎的,我松开了所有数组,只返回了第一个元素.
在我的代码中,我main调用一个动态需要创建数组的函数,在用户插入数组元素之后,所有数组都需要传递给函数funcdosomthing.
但目前函数funcdosomthing只获得第一个元素而不是所有数组.
只是为了说清楚其他一切都有效 - 当我不使用函数dynamic_arr并设置数组时,int a[] = {1, 0, 2};一切正常,函数funcdosomthing获取所有数组中的3个元素.
这是我的代码:
int *dynamic_arr(int n)
{
int i, *a;
a = (int*)calloc(n, sizeof(int));
for(i=0;i<n;i++) scanf("%d",a+i);
return a;
}
int mainprograma()
{
int n,*a,i;
scanf("%d",&n);
a=dynamic_arr(n);
funcdosomthing(a, sizeof a / sizeof a[0]);
...
Run Code Online (Sandbox Code Playgroud) 我在视图控制器中使用此功能来识别应用程序是否再次处于活动状态并刷新一些数据:
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(becomeActive:)
name:UIApplicationWillEnterForegroundNotification
object:nil];
Run Code Online (Sandbox Code Playgroud)
这可以在激活后进行刷新,但每次应用程序从后台返回到前台(非活动状态到活动状态)时,它会再次调用该函数.
因此,如果我关闭并打开应用程序4次,该功能将被调用4次!
编辑:该函数将以这种方式调用:
但它只需要在返回前景后被调用一次.在某些情况下,应用程序必须在激活并检查数据后显示警报视图.当该功能被调用4次时,此警报视图将显示4次.
在app委托中,这个函数什么都不做,但是它被提到了.
我正在使用Xcode 4.2和iOS 5!我也用过UIApplicationDidBecomeActive,但也会导致同样的问题.
我还是iOS开发的新手,我需要将google分析添加到我的phonegap项目中,但我不想使用javascript方式将其视为一个网站,我想使用Objective-C以正确的方式添加它.问题是每当我尝试添加谷歌分析文件和框架时,我都会收到以下错误:
Undefined symbols for architecture i386:
"_deflate", referenced from:
anon in libGoogleAnalyticsServices.a(NSData+zlib.o)
"_deflateEnd", referenced from:
anon in libGoogleAnalyticsServices.a(NSData+zlib.o)
"_deflateInit2_", referenced from:
anon in libGoogleAnalyticsServices.a(NSData+zlib.o)
"_inflate", referenced from:
anon in libGoogleAnalyticsServices.a(NSData+zlib.o)
"_inflateEnd", referenced from:
anon in libGoogleAnalyticsServices.a(NSData+zlib.o)
"_inflateInit2_", referenced from:
anon in libGoogleAnalyticsServices.a(NSData+zlib.o)
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Run Code Online (Sandbox Code Playgroud)
我也在使用admob与应用程序,但admob工作正常,我也尝试搜索重复文件的谷歌分析但找不到任何,当我尝试将谷歌分析添加到任何其他不包括phonegap的项目,它工作良好.请帮助我,我一直试图让这项工作持续2周.
如何char*在不创建数组并初始化数组的情况下将数组作为参数传递?
此代码有效(创建初始化代码):
char *messages[] = {"Zero", "One", "Two", "Three"};
printf("%s", messages[1]);
Run Code Online (Sandbox Code Playgroud)
但如果你这样传递它就不会起作用:
#include <stdio.h>
void printElement1(char *messages[]) {
printf("%s", messages[1]);
}
int main(void) {
printElement1({"Zero", "One", "Two", "Three"});
return 1;
}
Run Code Online (Sandbox Code Playgroud)
我不能使用a va_list,该函数接受一个char*数组就是这样.
ios ×6
objective-c ×5
iphone ×4
cocoa-touch ×3
c ×2
xcode ×2
arrays ×1
char ×1
cordova ×1
dataset ×1
opengl-es ×1
pointers ×1
uipicker ×1
uipickerview ×1
uitableview ×1
uiwebview ×1