git push 失败的解决办法(轉:方便自己查閱)
git push 失败的解决办法
假设执行操作:
1. 修改代码
2. git commit
3. git push
此时 push 失败(错误提示:! [rejected] master -> master (non-fast-forward) )
解决办法:
$ git pull
若成功,则:
$ git push origin master:your-id
完事。
若失败(提示:CONFLICT (content): Merge conflict in 文件名),则:
冲突的文件会有类似下面的代码块:
>commit id of others’
考虑你和他人对代码的修改,更新成合适的内容,并删除 3行标记符号,保存文件。
$ git commit -am “resolve conflict”
$ git push origin master:your-id
更详细的说明,可以阅读 $git push –help 该文档的 NOTE ABOUT FAST-FORWARDS 一节。
來自:http://www.cnblogs.com/baizx/archive/2010/08/09/1796124.html
如何将UIView转成UIImage 并保存到/读取应用目录
#import “QuartzCore/QuartzCore.h”
//把UIView 转换成图片
-(UIImage *)getImageFromView:(UIView *)view{
UIGraphicsBeginImageContext(view.bounds.size);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
-(IBAction)saveImage:(id)sender
{
UIImageView *image = [[UIImageView alloc] init];
image.image = [self getImageFromView:sview];
image.frame = CGRectMake(100, 20, 67, 215);
[...]
UINavigationController 不能响应 viewWillAppear等事件
最近在做一个应用,因为要在视图显示时做一些处理,发现UINavigationController 不能响应 viewWillAppear等事件,于是上网搜索了一下,最后找到原因!
先看官方文档说明:
viewWillAppear:
视图将要显示
Notifies the view controller that its view is about to be become visible.
通知视图控制器,视图将要显示了.
- (void)viewWillAppear:(BOOL)animated
Parameters
animated
If YES, the view is being added to the window using an animation.
Discussion
This method is called before the receiver’s view is about to be displayed onscreen and before any animations are configured for showing the view. You can override this [...]
给iphone应用Default.png添加效果
费话少说直接看代码
在你的应用代理中找到application didFinishLaunching,添加以下代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
//圖片擴大淡出的效果开始;
//设置一个图片;
UIImageView *niceView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, 320, 480)];
niceView.image = [UIImage imageNamed:@"Default.png"];
//添加到场景
[self.window addSubview:niceView];
//放到最顶层;
[self.window bringSubviewToFront:niceView];
//开始设置动画;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2.0];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:self.window cache:YES];
[UIView setAnimationDelegate:self];
//這裡還可以設置回調函數;
//[UIView setAnimationDidStopSelector:@selector(startupAnimationDone:finished:context:)];
niceView.alpha = 0.0;
niceView.frame = CGRectMake(-60, -85, 440, 635);
[UIView commitAnimations];
[niceView release];
//结束;
return YES;
}
xcode中添加环境变量跟踪
方便xcode测试可以在菜单中选中 product -> add Scheme中找到Run debug中添加以下环境变量
以此来跟踪变量,很方便
NSZombieEnabled YES
MallocStackLogging YES
MallocStackLoggingNoCompact Yes
在输出栏中输入:info malloc-history (十六进制变量名) 回车;
检测iphone内存泄漏-内存泄漏工具教程(译)
在国外的网站上看到了一个关于内存泄漏的文章,觉得不错就翻译了一下!
(译:随着我的游戏开发周期接近尾声我使用Instruments的次数也越来越多,”Instruments:Xcode自带的一组工具,所以结尾加了个S”因为我发现在这个工具用来在检测我的游戏内存泄漏超好用,于我就想写一篇关于如何用这个工具来检测内存泄漏的快速入门教程!PS:分享精神值得表扬!好同学啊!)
(内存泄漏?为什么要关注它?)
(内存泄漏是程序对已经分配的内存失去控制/跟踪,结果就会导致这个分配的内存永远无法被程序释放.会产生这些内存占用的情况一般是使用了:”new”,”malloc”,”alloc”而没有相对应的使用:”delete”,”free”,”release”,PS:还有”autorelease”)
(当你使用”new”,”malloc”,”alloc”的时候,操作系统就会从内存中划一块相应的内存出来供你使用,系统对你说:”给你,这是给你使用的那块内存的地址”.系统希望你保护好这个地址(引用址址,或者指针)并且相信你会在不用这个内存时告诉他.(用”delete”,”free”,”release”告诉系统,我不用这块内存了))
(内存泄漏发生在你把你的内存引用地址/指针给弄丢了,系统也就无法从你的一堆内存分醒中找出那里已经释放了,那些没有释放!)
(为什么要关注内存泄漏?大多数情况下当用户退出你的应用时你浪费的内存也会相应的释放,不会生产很大的影响,但是更差的就是程序运行时每帧都产生的内存泄漏,这将直接导致你的程序崩溃,特别是程序运行的时间很长的情况下!)
(想了解更多关于内存泄漏,可以直接去维基百科看下:)
http://en.wikipedia.org/wiki/Memory_leak
如何检测内存泄漏?
(有些内存泄漏可以直接看代码就能发现,但是有些就比较复杂,那么就该主角Instruments上场了,Instruments有一个”Leaks”的工具可以确切的告诉你什么地方发生了内存泄漏,你可以直接去这个地方修复!)
一个例子应用
(我准备好了有两个内存泄漏的应用,其中一处在Objective-C view controller中,还有一处在 C++ 的类中,你们可以到相应的地址下载,下面是代码片段)
InstrumentsTestViewController.mm Excerpts
// Leaky excerpts – see GitHub for complete source
- (void)viewDidLoad {
[super viewDidLoad];
LeakyClass* myLeakyInstance = new LeakyClass();
delete myLeakyInstance;
mMyLeakyString = [[NSString alloc] initWithUTF8String:”I’m a leaky string.”];
[self doSomethingNow];
}
- (void) doSomethingNow
{
mMyLeakyString [...]
cocos2d初探
pig = [CCSprite spriteWithFile:@"pig.png"];
pig.position = ccp(200,200);
[self addChild:pig];
// Import the interfaces
#import “HelloWorldScene.h”
#import “CCTouchDispatcher.h”
// HelloWorld implementation
@implementation HelloWorld
@synthesize themap;
@synthesize bgLayer;
@synthesize dude;
@synthesize stLayer;
+(id) scene
{
// ’scene’ is an autorelease object.
CCScene *scene = [CCScene node];
// ‘layer’ is an autorelease object.
HelloWorld *layer = [HelloWorld node];
// add layer as a child to scene
[scene addChild: layer];
// return the scene
return scene;
}
// on “init” you [...]
绝对比那些爱来爱去的小白脸歌星给力
伟大的祖-国她超有钱啊!
objective-c 第二课 数组 强化学习
1.新建数组,并添加元素;
#import
int main (int argc, const char * argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSMutableArray *myArray = [NSMutableArray array];
[myArray addObject:@"girl 1"];
[myArray addObject:@" girl 2"];
[myArray addObject:@" girl 3"];
int total = [myArray count];
NSLog(@”you have %d GF at the same time?”, count);
[pool release];
[...]
xCode objective-c视图和视图控制器之间怎么关联呢?
在xCode中,如果你想在界面上添加一个元件/元素,并要对元件进行控制;必须经过以下三个步骤:
1,在你的视图控制器类中添加元件声名,输出口声名;
//假设我想添加一个myButton(按钮);我必须这样写;
#import <UIKit/UIKit.h>
@interface youAppViewController : UIViewController {
UIButton *myButton;//元件声名;
}
@property(nonatomic,retain)IBOutlet UIButton *myButton;
//输出口声名;如果你要控制就要做这两步;
-(IBAction)myButtonPressed:(id)sender;//这是点击按钮的方法/事件;
@end
2,然后你的视图中添加你想要的元件;打开youAppViewController.xib;
按下花号銉(COMMAND)+L,调出库(Library);查找你要的组件;
如图:
你是不是觉得就这样好了?NO,这样才完成一半哦!
3,接下来要把我们的视图元件跟视图控制器声名绑定起来,你可以选中上图中的按钮,
然后按住Control 左击按钮不要松开拉一条线到 File’s Owner上面;
这时在File’s Owner上面会弹出一个小框,会显示你之前定义的方法 myButtonPressed,选中它就是把这个按钮绑定到这个方法了;
然后再反过来,从File’s Owner上面拖一条线到你的按钮上,选中你命名的按钮名字;
差不多就是这样了,你如果成功你可以看到这个:这里显示你的按钮相关信息,自己看看,你就明白了!