在我的应用程序中出现了一个奇怪的问题,它在加载我的启动画面之前显示黑屏一段时间.这个黑屏不是由于任何正在进行的操作,因为我首先加载我的启动画面然后开始我的xml解析任务.
我甚至尝试使用[window makeKeyAndVisible];但是徒劳无功.
这是'我的代码:
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
comingFromLogin = NO;
//Check For Internet
gotInternet = [self checkInternet]; //Test for Internet, calling the self method
if ( gotInternet == 0)
{
//I have no internet
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Sorry No Network Available" message:nil delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
// internetIcon.hidden = NO;
}
else
{
//I do have internet
[self didLoadSplashScreen];
}
}
-(void)didLoadSplashScreen
{
activity_indicator = [[ActivityIndicator alloc]initWithNibName:@"ActivityIndicator" bundle:nil];
splashScreen = [[splashScreenView alloc]initWithNibName:@"splashScreenView" bundle:nil];
splashScreen.view.alpha …Run Code Online (Sandbox Code Playgroud) 我试图阅读一些RSS数据.我有不同大小的数据.数据存在于tabke视图数据对象中.我使用标签添加数据并调整数据大小.没有成功.请帮忙.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
NSLog(@"in the tabel view cell");
heightOfCell=[self tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Default"];
if (cell == nil)
{
//cell = [[[UITableViewCell alloc] initWithFrame:CGRectMake(55.0,42.0,245.0,heightOfCell) reuseIdentifier:@"Default"] autorelease];
UILabel *label = [[UILabel alloc] init];
NSString *cellText = [[TableViewData news] valueForKey:[NSString stringWithFormat:@"%d",[indexPath row]]];
UIFont *cellFont = [UIFont fontWithName:@"Helvetica" size:10.0];
CGSize constraintSize = CGSizeMake(280.0f, MAXFLOAT);
label.text = [[TableViewData news] valueForKey:[NSString stringWithFormat:@"%d",[indexPath row]]];
CGSize labelSize = [[[TableViewData news] valueForKey:[NSString stringWithFormat:@"%d",[indexPath row]]] …Run Code Online (Sandbox Code Playgroud) 我不确定我在这里失踪了什么.我有一个自定义UINavigationController,我试图添加持久性UIBarButtonItem的酒吧.
-(void)viewDidLoad
{
self.navigationBar.barStyle = UIBarStyleBlack;
UIBarButtonItem *bbi = [[UIBarButtonItem alloc] initWithTitle:@"Nope..."
style:UIBarButtonItemStyleBordered
target:self
action:@selector(goBack:)];
self.navigationItem.leftBarButtonItem =bbi;
[bbi release];
}
-(void)goBack:(id)sender
{
NSLog(@"go back now");
}
我在这里失踪了什么? - 顺便说一句,我不想/不会使用IB.
更新:目前这是我能得到的最接近的:
-(void)viewDidLoad
{
self.navigationBar.barStyle = UIBarStyleBlack;
UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 20, 320, 44)];
navBar.barStyle = UIBarStyleBlack;
UINavigationItem *navItem = [[UINavigationItem alloc] initWithTitle:@"Currently Playing..."];
[navBar pushNavigationItem:navItem animated:NO];
UIBarButtonItem *editButton = [[UIBarButtonItem alloc] initWithTitle:@"Close" style:UIBarButtonItemStyleBordered target:self action:@selector(goBack:)];
navItem.rightBarButtonItem = editButton;
[self.view addSubview:navBar];
[editButton release];
[navItem release];
[navBar … 我有这个精灵,我试图检测用户是否触摸它并发布NSLOG.我已经阅读了一些关于在stackoverflow上检测精灵触摸的cocos2d帖子,但我有点困惑并且不太明白.任何帮助将不胜感激.我将在下面发布我的精灵.
chew = [CCSprite spriteWithFile:@"chew.png" rect:CGRectMake(0, 0, 152, 152)];
chew.position = ccp(100, 300);
[self addChild:chew];
Run Code Online (Sandbox Code Playgroud)
弄清楚了
-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSSet *allTouches = [event allTouches];
UITouch* touch = [touches anyObject];
CGPoint location = [touch locationInView: [touch view]];
location = [[CCDirector sharedDirector] convertToGL:location];
if (CGRectContainsPoint( [ chew boundingBox], location))
{
NSLog(@"touched");
}
}
Run Code Online (Sandbox Code Playgroud) 我的桌子相对简单,与以前的许多书架完全不同.然而didSelectRowAtIndexPath,只在表格的前5个单元格中调用.之后,点击时不会出现调试语句.我在这里研究了这个问题并排除了其他问题中提到的一些可能性: - 表委托是否正确设置.- a GestureRecognizer(我已设定)不会吞下印刷机.- willSelectRowAtIndexPath没有实施
以下是我的didSelectRowAtIndexPath.让我知道我能提供什么,可以帮助解决这个问题.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"didSelect");
NSArray *visibleCells = [partOfSpeechTable visibleCells];
UITableViewCell *cell = [visibleCells objectAtIndex:indexPath.row];
NSNumber *checkedState = [checkedStates objectAtIndex:indexPath.row];
if ([checkedState boolValue])
{
[cell setAccessoryType:UITableViewCellAccessoryNone];
[checkedStates setObject:[NSNumber numberWithBool:NO] atIndexedSubscript:indexPath.row];
}
else
{
[cell setAccessoryType:UITableViewCellAccessoryCheckmark];
[checkedStates setObject:[NSNumber numberWithBool:YES] atIndexedSubscript:indexPath.row];
}
[[tableView cellForRowAtIndexPath:indexPath] setSelectionStyle:UITableViewCellSelectionStyleNone];
}
Run Code Online (Sandbox Code Playgroud)
(我可以评论所有配件的东西,它没有任何区别).
谢谢你的帮助.
我的地图对象有一组坐标.它并不总是具有相同数量的坐标.在java中我只是声明对象,Double[] xpoints并在实例化这样的地图时设置它的大小:xpoints = new double[npoints];
我如何用objective-c做到这一点?
我试过这样做:@property(nonatomic) double * xpoints;但是当我用NSLog打印它时,它的所有值都会变为0.
地图的初始化:
-(id)initWithXpoints:(double[]) xpointss Ypoints:(double[]) ypointss Npoints:(int)npointss
{
self = [super init];
if (self)
{
self.xpoints = xpointss;
self.ypoints = ypointss;
self.npoints = npointss;
}
return self;
}
Run Code Online (Sandbox Code Playgroud)
虽然发生了一些奇怪的事情.当我从创建地图的对象打印xpoints [0]时,值将更改为零.我第一次打印它有效.第二次它只打印零.
我认为这是因为发送到init的xpointss已从内存中删除.如果它是指针,我如何"实例化"xpoints属性?
有一个更好的方法吗?
补充:我尝试创建一个像这样的临时xpoints:
double tempxpoints[npointss];
double tempypoints[npointss];
for (int i = 0; i < npointss; i++)
{
tempxpoints[i] = xpointss[i];
tempypoints[i] = ypointss[i];
}
self.xpoints = tempxpoints;
self.ypoints = tempypoints;
Run Code Online (Sandbox Code Playgroud)
但它仍然没有奏效.
编辑:谢谢你的所有答案.这最终成为我的最终Init代码:
-(id)initWithXpoints:(double[]) xpointss Ypoints:(double[]) …Run Code Online (Sandbox Code Playgroud) -(void) setupAVPlayerForURL:(NSString *)url
{
[appdelegate.sharedplayer stop];
appdelegate.sharedplayer=[[AVAudioPlayer alloc] initWithContentsOfURL:url1 error:NULL];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive: YES error: nil];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[appdelegate.sharedplayer setVolume:appdelegate.volumeDelegate];
[appdelegate.sharedplayer play];
self.seekBarSlider.minimumValue = 0.0f;
self.seekBarSlider.maximumValue = appdelegate.sharedplayer.duration;
self.isPlaying=YES;
appdelegate.sharedplayer.delegate=self;
[self loadAlbumArt];
[appdelegate.sharedplayer addObserver:self forKeyPath:@"status" options:0 context:nil];
}
Run Code Online (Sandbox Code Playgroud)
每当我运行此应用程序时,我会收到此日志消息,但第一次但应用程序没有崩溃
An instance 0xc1693d0 of class AVAudioPlayer was deallocated while key value observers were still registered with it.
Observation info was leaked, and may even become mistakenly attached to some other object. Set a breakpoint on NSKVODeallocateBreak …Run Code Online (Sandbox Code Playgroud) 我有一个tableview,我动态地返回每个部分的部分和行没有.我可以像这样实现它
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if( section == 0)
return [array count];
if( section == 1)
return [array2 count];
if( section == 2)
return [array3 count];
}
Run Code Online (Sandbox Code Playgroud)
如果我知道我有3个部分,我可以用上面提到的方式做到这一点.但是如何动态定义不同部分的行数.例如: - 你有if(section == 0).我不想在这里硬编码0,1,2的值.我不确定部分的总数.我们怎么做呢我们想为不同的部分动态返回行数?我有一个数组显示没有部分和不同的数组,以显示每个部分没有行.如何在方法"numberOfRowsInSection"中动态提及?
非常熟悉Android编程,但对iOS(和Objective-C)来说是非常新的.
我在我的应用程序中调用一个远程php文件,并且(我相信)根据我的NSLOG结果成功解析了JSON结果.例:
2013-01-17 14:24:30.611 JSON TESTING 4[1309:1b03] Deserialized JSON Dictionary = {
products = (
{
BF = "";
EN = "2342";
Measure = ft;
Name = "Brian";
"Name_id" = 1;
Home = "New York";
"DB_id" = 1;
},
{
BF = "";
EN = "2123";
Measure = ft;
Name = "Rex";
"Name_id" = 3;
Home = "New York";
"DB_id" = 5;
}
);
success = 1;
Run Code Online (Sandbox Code Playgroud)
}
我的问题在于如何将这些信息填充到表格视图中.我可以自定义一个原型单元,但是我从哪里开始呢?
编辑:
这是我的视图设置代码:
#pragma mark - Table View
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section …Run Code Online (Sandbox Code Playgroud) 我想animations在我的实施中实施application.我只想尝试一个简单的旋转button.按钮本身rotated,但它也改变了它的位置,旋转角度与我想要的不同.我也加了autoresizesSubwievs = NO;
- (IBAction)rotateView:(id)sender
{
[UIView animateWithDuration:0.6f delay:0.1 options:UIViewAnimationOptionCurveEaseOut animations:^{
self.view.autoresizesSubviews = NO;
[self.buttoner setTransform:CGAffineTransformRotate(self.buttoner.transform, 90.0f)];
} completion:nil];
}
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?你能帮我么?
编辑:我有两个按钮,当第一个按下时,我调用上面的方法...但这会导致移动第一个按钮,然后移动第二个按钮并以不适当的角度旋转它.我根本不明白..
objective-c ×7
ios ×6
iphone ×4
uitableview ×3
animation ×1
avplayer ×1
cocoa-touch ×1
json ×1
nsdictionary ×1
rotation ×1