有人可以建议今天这些图书馆的最佳用途是什么吗?它只是GUI,还是有数据库,XML,网络,线程等支持?
我正在阅读他们,并考虑开始学习/使用其中一个.
什么是最常见的?他们之间有什么区别?你为什么选择一个而不是另一个?
我对C++非常熟悉,所以我考虑学习.NET及其所有衍生物(尤其是C#).
一路上我遇到了C++/CLI,我想知道该语言是否有任何特定用途?它只是假设是从原生C++转换为C#的中间语言吗?
突然出现的另一个问题是为什么.NET框架中仍有这么多编程语言?(VB,C++/CLI,C#...)
我正在尝试定义一个宏,假设它采用2个字符串值并返回它们之间的一个空格连接.似乎我可以使用除空间之外我想要的任何角色,例如:
#define conc(str1,str2) #str1 ## #str2
#define space_conc(str1,str2) conc(str1,-) ## #str2
space_conc(idan,oop);
Run Code Online (Sandbox Code Playgroud)
space_conc 将返回"idan-oop"
我想要一些东西回归"idan oop",建议?
我找不到一个体面的答案来解释我这两个功能之间的区别.每个人什么时候被召唤,一个人与另一个人有什么不同?
例如,我不能只是将我的视图布局在drawrect中吗?
谢谢
我正在设计使用IB特定按钮(带有一些标签,以及imageView和其他东西).
我想在另一个xib中使用那个xib对象(按钮),其中我有6个该按钮的对象.
我知道我可以使用类标识符以编程方式执行此操作,但是我必须定位我的标签和图像视图,并在代码中设置默认值和其他所有内容.
我想知道是否有可能只使用IB做同样的事情?(当然我仍然会在代码中设置值,但我想要在lable/imageView的位置以及所有其余的在xib中设置)
谢谢
编辑
所以,我理解我最初要求的是不可能的.我现在正在尝试的是这样的:
我创造了一个ButtonTest.xib.在Xib里面我有一个UIView和3个子视图(2个标签和一个按钮).在检查器中,我将UIView类设置为ButtonTest.在ButtonTest.m内部,每个子视图都有3个出口,我在IB中连接.
接下来我有一个ButtonTestViewController.xib.在里面我放了一个视图,并在检查器中设置它的类ButtonTest.我将该视图连接到课堂myTextView内ButtonTestViewController.m的插座ButtonTest
现在,这是ButtonTestViewController.m viewDidLoad中的代码:
- (void)viewDidLoad {
[super viewDidLoad];
NSArray *subviewArray = [[NSBundle mainBundle] loadNibNamed:@"ButtonTest" owner:nil options:nil];
ButtonTest *mainView = (ButtonTest*)[subviewArray objectAtIndex:0];
self.myTextView = mainView;
}
Run Code Online (Sandbox Code Playgroud)
我希望会发生的是,ButtonTestViewController.xib中的视图将成为我在ButtonTest.xib中设计的视图.这不会发生.会发生什么是ButtonTestViewController.xib中的视图保持不变.
值得一提的是,如果我添加:
[self.view addSubview:mainView];
Run Code Online (Sandbox Code Playgroud)
它除了现有视图外,还添加了新视图.
知道怎么做我想要的吗?
最终我希望有6个视图ButtonTestViewController.xib,所有看起来都像ButtonTest.xib模板,并且lables值将在代码中设置.
EDIT2
好吧,伙计们,我做了你所说的一切,它就像一个魅力.我现在遇到这个问题的唯一问题是当视图中的视图比视图ButtonTestViewController.xib大一点时ButtonTest.xib.当发生这种情况时,按钮上的标签看起来非常模糊.当它们都是相同的尺寸时,一切都很好.
@Ned - 我使用了你在我的InitWithCoder方法中发布的确切代码,除了我将框架句子切换为:
self.bounds = mainView.frame;
Run Code Online (Sandbox Code Playgroud)
我尝试使用IB中的内容模式尝试修复它,但无济于事.
当我像你发布的那样使用它时,意思是:
mainView.frame = self.bounds;
Run Code Online (Sandbox Code Playgroud)
它根本不起作用,两个视图的大小保持不变.在这里,我尝试使用resizeMask但仍然无法正常工作.
并想出如何解决这两个问题?多谢你们!
编辑3
我确实设法修复了其中一个问题,调整ButtonTestViewController.xib了ButtonTest.xib视图大小.这就是我所做的(使用代码解决模糊问题,取自 …
我在网上看到了一些材料,但仍然无法到达我想要的地方.我需要向下调整我的视图,使其高度更大.
到目前为止,这是我的代码.这里发生的事情是,不是我的视图调整大小,它只是改变了它的位置.如果我将proprty而不是"bounds.size"更改为"transform.scale.y",它会更好一些,只是这次它会向上和向下扩展视图,而不仅仅是向下扩展.
另一件事我不是:这些键只是CALayer属性吗?在哪里可以找到这些键的列表?
我真的很感激这里的帮助.谢谢!
int x = self.btnHead.frame.origin.x;
int y = self.btnHead.frame.origin.y;
int height = self.btnHead.frame.size.height;
int width = self.btnHead.frame.size.width;
CABasicAnimation *resizeAnimation = [CABasicAnimation animationWithKeyPath:@"bounds.size"];
[resizeAnimation setToValue:[NSValue valueWithCGSize:CGSizeMake(width,height+50)]];
resizeAnimation.fillMode = kCAFillModeForwards;
resizeAnimation.removedOnCompletion = NO;
CAAnimationGroup *animationGroup = [CAAnimationGroup animation];
animationGroup.animations = [NSArray arrayWithObjects:resizeAnimation,nil];
animationGroup.removedOnCompletion = NO;
animationGroup.fillMode = kCAFillModeForwards;
animationGroup.removedOnCompletion=NO;
animationGroup.duration = 0.1;
[self.btnHead.layer addAnimation:animationGroup forKey:@"animations"];
Run Code Online (Sandbox Code Playgroud)
编辑:按要求发布我的第一个代码 - 这只会改变我的视图大小,但无论我输入的持续时间都不会动画.
int x = self.btnHead.frame.origin.x;
int y = self.btnHead.frame.origin.y;
int height = self.btnHead.frame.size.height;
int width = self.btnHead.frame.size.width;
[UIView beginAnimations:nil context:nil];
[UIView …Run Code Online (Sandbox Code Playgroud) 我想分配一个矩阵.
这是唯一的选择:
int** mat = (int**)malloc(rows * sizeof(int*))
for (int index=0;index<row;++index)
{
mat[index] = (int*)malloc(col * sizeof(int));
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试从表格视图中获取特定单元格,以便我可以更改它的标签并停止活动指示器.
我遇到的问题是cellForRowAtIndexPath返回零.
我的表视图只有一行.
代码:
- (id) initWithNibName: (NSString*) nibNameOrNil bundle: (NSBundle*) nibBundleOrNil
{
self = [super initWithNibName: nibNameOrNil bundle: nibBundleOrNil];
if (self)
{
numberOfRows = 1;
}
return self;
}
- (NSInteger) tableView: (UITableView*) tableView numberOfRowsInSection: (NSInteger) section
{
return numberOfRows;
}
-(void) stopCellIndicator
{
LiveUserFeedCell* cell = (LiveUserFeedCell*)[self.liveFeed cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
[cell.activityIndicator stopAnimating];
cell.middleLabel.text = @"N/a";
}
- (UITableViewCell*) tableView: (UITableView*) tableView cellForRowAtIndexPath: (NSIndexPath*) indexPath
{
static NSString *CellIdentifier = @"UserFeedCell";
LiveUserFeedCell *cell = (LiveUserFeedCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; …Run Code Online (Sandbox Code Playgroud) 我有一个voip应用程序,它也在后台运行.当我在后台时,我正在从主线程调用:(在我诊断网络丢失的情况下建立网络连接).
[self performSelector :@selector(Reconnect:) withObject:nil afterDelay:60.0];
Run Code Online (Sandbox Code Playgroud)
但是,只有当我的应用程序返回到前台时才会执行选择器.我应该做些什么来让选择器在后台执行吗?
谢谢
编辑:
-(void) reconectInBackgroundAfterDelay:(NSTimeInterval) dealy
{
NSLog(@"reconectInBackgroundAfterDelay");
UIApplication* app = [UIApplication sharedApplication];
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}];
// Start the long-running task and return immediately.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[self performSelector :@selector(Reconnect:) withObject:nil afterDelay:dealy];
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
});
}
Run Code Online (Sandbox Code Playgroud)
我添加了这个代码,但仍然没有在提供的延迟后调用"重新连接"方法.我已经在后台调用"reconectInBackgroundAfterDelay"方法.
还有其他建议吗?
编辑2 找到解决方案.见下文
所以,我有两种类型的数据,一些需要持久化,一些不需要.
我正在考虑将所有网络相关代码放在我的UIViewControllers中,所有网络请求从哪里开始,或者在另一层中.
我的想法是:
有一个叫做的图层NetworkManager.
NetworkManager是我所有网络服务电话的歌手.
对于需要持久且可以在列表中显示的数据,我会让网络管理员发出请求,将响应保存在我的本地核心数据DB中,然后使用我的UIViewController数据来监听FetchResultsController.
但是,还有许多其他类型的请求.例如:登录请求,用户信息请求,friendsNearBy等等...有些不必在我的数据库中持久化,有些不适合FRC架构.
对于这些类型的请求,据我所知,有两种处理方式:
1.使用另一个层来分隔ViewControllers和NetworkManager.我们称之为Mediator.该Mediator如果有别的需要与它做,然后发布适当的名称和数据的通知会从NetworkManager的字典(JSON)的请求,决定根据应用程序的逻辑.如果中介保存发出请求的UIViewController,它可以直接将响应委派给他而不是发布通知.
流程将是这样的:
MyUiViewController - > Mediator -> NetworkManger->Mediator-> PostNotification (or directly back to MyUiViewController)
Pros:
Decoupling
Nice structure and separation of concerns
Cons:
Harder to code
Sometimes harder to understand and debug.
Run Code Online (Sandbox Code Playgroud)
2.没有这种3层架构,而是拥有MyUiViewControllers,用块发出网络请求.意思是代替Mediator拦截MyUiViewController之前的响应,让MyUiViewController使用块处理响应,因为他是发布它的人.
Pros:
Simple and quick to code
Easy to understand
Cons:
Coupling of network code inside your controllers
Run Code Online (Sandbox Code Playgroud)
我希望从人们的经验或其他/更好的方式获得最佳建议和评论.