小编ban*_*ing的帖子

iOS 5中的Singleton?

嗨我有一个实现以前版本的iOS的单身如下:

.h文件

@interface CartSingleton : NSObject 
{

}
+(CartSingleton *) getSingleton;
Run Code Online (Sandbox Code Playgroud)

.m文件

@implementation CartSingleton

static CartSingleton *sharedSingleton = nil;

+(CartSingleton *) getSingleton
{
    if (sharedSingleton !=nil)
       {
        NSLog(@"Cart has already been created.....");
        return sharedSingleton;
       }
    @synchronized(self)
   {
    if (sharedSingleton == nil)
       {
        sharedSingleton = [[self alloc]init];
        NSLog(@"Created a new Cart");
       }
   }
    return sharedSingleton;
}
//==============================================================================
+(id)alloc
{
    @synchronized([CartSingleton class])
   {
    NSLog(@"inside alloc");
    NSAssert(sharedSingleton == nil, @"Attempted to allocate a second instance of a singleton.");
    sharedSingleton = [super alloc];
    return …
Run Code Online (Sandbox Code Playgroud)

singleton objective-c ios5

11
推荐指数
2
解决办法
1万
查看次数

如何使UITableViewCell突出显示状态持久化

我有一个UITableviewCell.当用户单击该单元格时,我保存索引路径,然后调用cellforrowAtIndexpath方法获取单元格,然后在该单元格上调用SetHighlighted:TRUE.

这工作正常,但问题是当我在桌面视图中上下滚动时,重新出现时所选单元格不会突出显示.如何使突出显示的蓝色颜色保持不变,这样即使向上或向下滚动表格,用户也可以直观地看到他们的选择?

谢谢

iphone uitableview

10
推荐指数
1
解决办法
7753
查看次数

如何从rails应用程序中的assets/images文件夹中获取图像

我一直在寻找并寻找这个答案.但是现在几个小时我似乎无法完成这项工作.请帮帮我.

我是我的rails应用程序的网页,我正在尝试显示保存在我的资源文件夹中的图像 @app/assets/images/rails.png.

我有一个javascript文件,其中包含构造html的以下函数.在这个函数里面,我想把链接传递给图像.这是我目前的代码.

function addToInfoWindow(infoWindowContent)
{

infoWindowString = '<div class="infoWindow">'+
**'<img src="/assets/images/rails.png" />'+**
'<p>'+infoWindowContent+'</p>'+
'<p><a href="http://www.google.com">See here</a></p>'+
'<p><a href="http://www.google.com">Upload a photo</a></p>'+
'</div>';
infoWindow.setContent(infoWindowString);

}
Run Code Online (Sandbox Code Playgroud)

正如您在代码中看到的那样,粗体部分就是问题所在.我已经尝试了几种不同的url字符串组合来访问该图像文件,但图像没有显示在html元素中.

我看了看,尝试过rails帮助函数等image_url('rails.png').但我必须把它们放在错误的地方.有人可以帮帮我吗.请告诉我上面的代码中我需要添加什么函数来获取图像,/assets/images/rails.png以便将它的url放在上面突出显示的部分中,并在我的视图中显示.

javascript ruby ruby-on-rails infowindow

10
推荐指数
1
解决办法
1万
查看次数

正确使用ruby字符串中的gsub

我有这个表达式:

channelName = rhash["Channel"].gsub("'", " ")
Run Code Online (Sandbox Code Playgroud)

它工作正常.但是,我只能用它替换1个字符.我想为替换添加一些字符.所以我尝试了以下方法:

channelName = rhash["Channel"].gsub(/[':;] /, " ")
Run Code Online (Sandbox Code Playgroud)

这不起作用,即没有对字符串进行替换,也没有错误消息.我也试过这个:

channelName = rhash["Channel"].gsub!("'", " ")
Run Code Online (Sandbox Code Playgroud)

这导致一个空白的字符串.所以绝对不是我想要的.

我想有一个gsub方法用我的字符串中的空格替换以下字符:

 ' ; :
Run Code Online (Sandbox Code Playgroud)

我的问题:

  1. 如何构建我的gsub方法,以便用空格替换上述字符的所有实例?

  2. gsub发生了什么事!以上为空白.

ruby string gsub

9
推荐指数
2
解决办法
3万
查看次数

MySQL数据库数据类型

我是数据库编程的新手,我有一个非常基本的问题:

在我用于在我的数据库中创建表的PHPMyAdmin GUI中,当"type"(即.atatatype)列具有数据类型并且之后括号中的内容时,它意味着什么.例如:int(20),bigint(30).....

我理解int和bigint类型意味着使用的字节数,因此意味着可以存储的值的范围.但括号中的值是什么意思?

(20)和(30)代表什么......这对...有什么影响......

对不起,如果Q是基本的,我试图了解数据库....

非常感谢

mysql database data-structures

8
推荐指数
1
解决办法
1448
查看次数

对于Rails视图*.html.erb:我可以在哪里放置样式表?

我有这个文件:

app/views/listings/list.html.erb
Run Code Online (Sandbox Code Playgroud)

在我的rails项目中.以下是该文件的内容:

<h1>This file is:"list.html.erb"</h1>  

<!DOCTYPE html>  
<html>  
  <head>  
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />  
    <style type="text/css">  
      html { height: 100% }  
      body { height: 100%; margin: 0; padding: 0 }  
      #map_canvas { height: 100% }  
    </style>  
    <script type="text/javascript"  
      src="http://maps.googleapis.com/maps/api/js?key=key&sensor=false">  
    </script>  

    <%=javascript_include_tag 'application'%>  
  </head>  
  <body onload="initialize()">  
    <div id="map_canvas" style="width:80%; height:80%"</div>    
    <input type="button" onclick="getlistings();" value="Add Markers">   
    <input type="button" onclick="clearMarkers();" value="Remove Markers">   
  </body>  
</html>  
Run Code Online (Sandbox Code Playgroud)

我喜欢将样式表应用于它.我应该在哪里放置样式表?我尝试将代码放在此文件中:

app/assets/stylesheets/listings.css.scss
Run Code Online (Sandbox Code Playgroud)

但该样式未应用于html文件.我还需要更改我的html视图文件中的任何内容以包含样式表吗?

这是位于以下位置的样式表:"app/assets/stylesheets/listings.css.scss"

// Place all the styles related to the Listings controller here.  
// They will …
Run Code Online (Sandbox Code Playgroud)

css ruby-on-rails

8
推荐指数
1
解决办法
3万
查看次数

无法在Mountain Lion上安装pg gem

升级到Mountain Lion后,我遇到了很多关于Rails的麻烦.

到目前为止,我试图解决这些问题并在互联网上搜索几个小时我已经做了以下工作以确保我的系统在升级后具有运行rails的所有依赖关系:

  1. 我更新了我的Homebrew安装
  2. 我更新了我的RVM安装
  3. 我安装了XCode命令行工具
  4. 按照提到安装了GCC
  5. 我将我的Ruby版本升级为

    ruby 1.9.2p290(2011-07-09修订版32553)[x86_64-darwin10.8.0]

  6. 我的Rails版本被验证为Rails 3.2.6
  7. 我还发现Mountain Lion与Postgres有一些问题,所以我看到这篇文章,发现我需要将这一行添加到我的Bash配置文件中:

    export PATH="/usr/local/bin:/usr/bin:$PATH"
    
    Run Code Online (Sandbox Code Playgroud)

现在我转到我升级之前在Snow Leopard上运行正常的Rails应用程序,当我rails s在命令行运行时出现以下错误:

AM@~/Documents/RailsWS/app0815 >gem install pg
 Building native extensions.  This could take a while...
 ERROR:  Error installing pg:
 ERROR: Failed to build gem native extension.
 /Users/AM/.rvm/rubies/ruby-1.9.2-p290/bin/ruby extconf.rb
 checking for pg_config... yes
 Using config values from /usr/bin/pg_config
 checking for libpq-fe.h... *** extconf.rb failed ***
 Could not create Makefile due to some reason, probably lack of
 necessary libraries and/or …
Run Code Online (Sandbox Code Playgroud)

postgresql macos ruby-on-rails osx-mountain-lion

8
推荐指数
2
解决办法
6345
查看次数

在Singleton Objective C中删除NSNotificationCenter的观察者

快速提问:

我有一个单例类,它注册了几个NSNotifications.因为Singletons持续超过应用程序的生命周期.

我必须实施吗?

  [NSNotificationCenter defaultCenter] removeObserver:self] 
Run Code Online (Sandbox Code Playgroud)

在我的单身课程中?

什么是在iOS中与Singletons中的NSNotification中心打交道的正确方法?

谢谢

singleton objective-c nsnotificationcenter ios

8
推荐指数
1
解决办法
2128
查看次数

如何在rails版本3.2.1中注释rails模型

我试着按照一些关于在rails中注释我的模型的在线教程.然而,似乎所有的教程都在讨论过时的注释版本或不正确的安装它是一团糟.

到目前为止,我尝试了以下内容

1)在Gemfile中添加了这个

gem 'annotate', '2.4.0'
Run Code Online (Sandbox Code Playgroud)

2)然后命令:

bundle install
Run Code Online (Sandbox Code Playgroud)

3)然后我看到安装了注释gem并显示在命令上

bundle show
Run Code Online (Sandbox Code Playgroud)

4)最后,为了注释我的模型,我使用了命令

bundle exec annotate --position before
Run Code Online (Sandbox Code Playgroud)

在这一点上,我期待我的模型被注释,但我得到的是以下错误消息:

/Users/AM/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/railties/databases.rake:4:in `<top (required)>': undefined method `namespace' for main:Object (NoMethodError)
from /Users/AM/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/railtie.rb:33:in `load'
from /Users/AM/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/railtie.rb:33:in `block in <class:Railtie>'
from /Users/AM/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.1/lib/rails/railtie.rb:184:in `instance_exec'
from /Users/AM/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.1/lib/rails/railtie.rb:184:in `block in load_tasks'
from /Users/AM/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.1/lib/rails/railtie.rb:184:in `each'
from /Users/AM/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.1/lib/rails/railtie.rb:184:in `load_tasks'
from /Users/AM/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.1/lib/rails/engine.rb:423:in `block in load_tasks'
from /Users/AM/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.1/lib/rails/application/railties.rb:8:in `each'
from /Users/AM/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.1/lib/rails/application/railties.rb:8:in `all'
from /Users/AM/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.1/lib/rails/engine.rb:423:in `load_tasks'
from /Users/AM/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.1/lib/rails/application.rb:145:in `load_tasks'
from /Users/AM/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.1/lib/rails/railtie/configurable.rb:30:in `method_missing'
from Rakefile:7:in `<top (required)>'
from /Users/AM/.rvm/gems/ruby-1.9.2-p290/gems/annotate-2.4.0/lib/annotate.rb:17:in `load'
from /Users/AM/.rvm/gems/ruby-1.9.2-p290/gems/annotate-2.4.0/lib/annotate.rb:17:in `load_tasks' …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails annotate

6
推荐指数
1
解决办法
3192
查看次数

获取Action控制器未知格式错误 - 用于rails 4 +不引人注目的javascript和AJAX调用

我有以下设置:

uploads_controller.rb:

 class UploadsController < ApplicationController
    before_action :set_upload, only: [:show, :edit, :update, :destroy] 

   # GET /uploads
   def index
     @uploads = Upload.all
 update_file_status
 @uploads = Upload.all
   end

  # GET /uploads/1
  def show
  end

  # GET /uploads/new
  def new
puts "Running uploads/new"
   @upload = Upload.new()
  end

 # GET /uploads/1/edit
def edit
end

# POST /uploads
def create

@upload = Upload.new(upload_params)
if @upload.save
    @upload.update!(:status => "1")
    @upload.update!(:f_path => "#{@upload.sourcedata.path}")
    redirect_to uploads_url, notice: "Upload for #{@upload.task.name} was successfully created with file #{@upload.sourcedata_file_name}."
    else
       redirect_to …
Run Code Online (Sandbox Code Playgroud)

javascript ajax ruby-on-rails unobtrusive-javascript actioncontroller

6
推荐指数
1
解决办法
2万
查看次数